Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Add error to negotiate #2998

Merged
merged 3 commits into from
Sep 28, 2018
Merged

Add error to negotiate #2998

merged 3 commits into from
Sep 28, 2018

Conversation

BrennanConroy
Copy link
Member

#2988

No httpclient testability in Java yet.

private JsonParser jsonParser = new JsonParser();

public NegotiateResponse(String negotiatePayload) {
JsonObject negotiateResponse = jsonParser.parse(negotiatePayload).getAsJsonObject();
if (negotiateResponse.has("error")) {
this.error = negotiateResponse.get("url").getAsString();
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the parsing logic should exit early like this. You're right that an error property generally means everything else should be ignored, but let the caller decide that.

@@ -428,6 +428,10 @@ private async Task<NegotiationResponse> NegotiateAsync(Uri url, HttpClient httpC
{
negotiateResponse = NegotiateProtocol.ParseResponse(responseStream);
}
if (!string.IsNullOrEmpty(negotiateResponse.Error))
{
throw new InvalidOperationException(negotiateResponse.Error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InvalidOperationException isn't really right here... We don't know anything about the underlying problem, it's no better than just throwing Exception.

@@ -62,6 +62,19 @@ The `POST [endpoint-base]/negotiate` request is used to establish a connection b
* The `url` which is the URL the client should connect to.
* The `accessToken` which is an optional bearer token for accessing the specified url.


3. A response that contains an `error` which should abort the connection attempt.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change abort to stop.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we need a protocol version here @anurse

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's not a bad idea. But do we want to do the two-part handshake that ASP.NET SignalR does? Where the client reports it's max supported version?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERRR, I hope we don't need to change it that much.

Copy link
Contributor

@mikaelm12 mikaelm12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this wait for HttpClient testing in the Java client? #3011

@BrennanConroy
Copy link
Member Author

No

return ResponseUtils.CreateResponse(HttpStatusCode.OK,
JsonConvert.SerializeObject(new
{
error = "Negotiate failed."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Change this error message to something that isn't about negotiation. This seems like something that could be ambiguous

this.connectionId = reader.nextString();
break;
default:
// Skip unknown property, allows new clients to still work with old protocols
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a test case for this assertion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+have a test case for skipping a simple value, e.g. "a string!", and a complex value, e.g. ["array", "of", "content"]

I'm guessing skipValue will skip all of the complex value but it is worth double checking. It is a common bug I've seen in code that manually reads JSON

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do now, both cases. Thanks James

@BrennanConroy
Copy link
Member Author

@dotnet-bot test Windows Release Spanish Language x64 Build

@BrennanConroy BrennanConroy merged commit 1f91b52 into release/2.2 Sep 28, 2018
@BrennanConroy BrennanConroy deleted the brecon/negotiateError branch September 28, 2018 03:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants