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

Exceptions thrown for non-200 code #155

Open
samrueby opened this issue Aug 22, 2019 · 0 comments
Open

Exceptions thrown for non-200 code #155

samrueby opened this issue Aug 22, 2019 · 0 comments

Comments

@samrueby
Copy link

When Google responds with an error, for example with the Geocoding API, they respond with JSON describing the problem, but also set the HTTP status code to 400. gmaps-api-net uses HttpClient, which throws for non-200 codes, and doesn't catch them.

Example Google response with 400 code:
{
"error_message" : "Invalid request. Missing the 'address', 'components', 'latlng' or 'place_id' parameter.",
"results" : [],
"status" : "INVALID_REQUEST"
}

Stack trace when this happens:
System.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request).
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Maps.Internal.MapsHttp.d__4`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Maps.Internal.MapsHttp.Get[T](Uri uri)

What should be happening instead:
gmaps-api-net should be handling the non-200 code and instead returning the appropriately deserialized GeocodeResponse type, which will have the ServiceResponseStatus Status field set to InvalidRequest.

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

No branches or pull requests

1 participant