Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include NSError code, domain and HTTP Status code in DarwinWebSocketException message #209

Merged
merged 10 commits into from
May 18, 2022

Conversation

remy-bardou-lifeonair
Copy link
Contributor

When something went wrong in the web socket handshake on iOS, it's hard to understand why.
That's because the description available with DarwinWebSocketException only comes from NSError.localizedDescription.

Such example, when hitting a 401 error would be There was a bad response from the server..

NSError has a domain and errorCode available, that a developer can look up in the Apple documentation to get more context on. Furthermore, it is usually very helpful to know the HTTP Status code.

So my proposal is to improve the exception text to include all those data points.

This was tested successfully on iOS by trying to connect to a web socket endpoint that requires authentication and not provide any headers.
I observed the following logs as a result: NSURLErrorDomain -1011: There was a bad response from the server. (HTTP Status Code: 401), which see more actionable to me as a developer.

@joffrey-bion
Copy link
Owner

joffrey-bion commented May 16, 2022

Thanks a lot for the suggestion and the PR!

The NSError is actually already provided as a property on DarwinWebSocketException so when catching this exception you can log the error code or base your handling logic on it (by the way you removed this in the PR, which is a breaking change and is not desirable IMO).

Do I understand correctly that your use case is not about getting information from the exception object (in code), but rather seeing a more informative message when it crashes? In that case I definitely agree we can change the error message in the way you did in the PR.

The HTTP status code is slightly more debatable, because it only applies during the HTTP handshake for the upgrade to web socket protocol, but this exception is supposed to represent any error on the websocket. That said, we can be pragmatic and add it too, because it is indeed useful to debug connection issues (which in all honesty probably represent a significant proportion of all errors :D).

@joffrey-bion joffrey-bion changed the title Include NSError code, domain and HTTP Status code in DarwinWebSocketException Include NSError code, domain and HTTP Status code in DarwinWebSocketException message May 16, 2022
@joffrey-bion
Copy link
Owner

joffrey-bion commented May 17, 2022

@remy-bardou-lifeonair If you don't have time to discuss this, that's completely ok. Just let me know, because in this case I will merge this PR and make adjustments on top myself before releasing it

@remy-bardou-lifeonair
Copy link
Contributor Author

@remy-bardou-lifeonair If you don't have time to discuss this, that's completely ok. Just let me know, because in this case I will merge this PR and make adjustments on top myself before releasing it

no worries, it's just my email notifications are not setup properly so I hadn't seen your feedback yet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants