Skip to content
This repository was archived by the owner on Sep 1, 2025. It is now read-only.

Conversation

@hopsor
Copy link

@hopsor hopsor commented Dec 2, 2019

https://stuart-team.atlassian.net/browse/INT-9

We've identified that when making http request calls and there is a 500 error for instance the function to_api_response always tries to parse the json which ends up raising an Jason.DecodeError exception.

With this change we return the tuple error instead. We will adapt monocle code afterwards to adapt it to this change.

%{status_code: status_code, body: Jason.decode!(body)}
with {:ok, decoded_body} <- Jason.decode(body) do
%{status_code: status_code, body: decoded_body}
else
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can get rid of this else, because the default behavior of a with clause is returning what doesn't match. Unless we're doing a special treatment of the error, logging it, etc., we don't need the else.

Copy link
Contributor

@jaimeiniesta jaimeiniesta left a comment

Choose a reason for hiding this comment

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

LGTM! I think the only case where we want to handle a non-JSON response is already handled for the 204 status code above. 👍

@hopsor hopsor merged commit d1a44d5 into develop Dec 3, 2019
@hopsor hopsor deleted the chore-handle-decode-errors branch December 3, 2019 14:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants