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

Improve handling of non-JSON errors. #166

Merged
merged 3 commits into from
Aug 23, 2024
Merged

Improve handling of non-JSON errors. #166

merged 3 commits into from
Aug 23, 2024

Conversation

plietar
Copy link
Member

@plietar plietar commented Aug 22, 2024

When getting a non-200 HTTP response, orderly tries to decode the body as JSON in order to extract the error message. We do however occasionally get errors that aren't JSON formatted, in particular if the error is generated by nginx rather than Packit.

This situation can arise if the Packit server is down (a 503 error), or if nginx rejects the request due to the body being too large (a 413 error).

We can use the content type header of the response to determine whether it is safe to decode the body as JSON. If the response is not of the expected mime-type, the body is ignored and a generic error based on the status code alone is returned.

When getting a non-200 HTTP response, orderly tries to decode the body
as JSON in order to extract the error message. We do however
occasionally get errors that aren't JSON formatted, in particular if the
error is generated by nginx rather than Packit.

This situation can arise if the Packit server is down (a 503 error), or
if nginx rejects the request due to the body being too large (a 413
error).

We can use the content type header of the response to determine whether
it is safe to decode the body as JSON. If the response is not of the
expected mime-type, the body is ignored and a generic error based on the
status code alone is returned.
@plietar plietar requested a review from richfitz August 22, 2024 16:21
Copy link
Member

@richfitz richfitz left a comment

Choose a reason for hiding this comment

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

one inline suggestion to appease the linter, otherwise LGTM

tests/testthat/helper-outpack-http.R Outdated Show resolved Hide resolved
@plietar plietar force-pushed the mrc-5706-error-no-json branch from 3876501 to 47e81c2 Compare August 23, 2024 13:07
@plietar plietar merged commit 6977728 into main Aug 23, 2024
10 checks passed
plietar added a commit that referenced this pull request Sep 5, 2024
In some circumstances, Packit returns an HTTP error with no body and no
Content-Type header. In those cases, httr2 returns NA as the
content type.

#166 added a check to make sure the content type is JSON before decoding
the error, however the check did not handle NA values properly and gave
a `missing value where TRUE/FALSE needed`.

This now uses `identical` instead of `==` to compare the content type
string against the expected string.
plietar added a commit that referenced this pull request Sep 5, 2024
In some circumstances, Packit returns an HTTP error with no body and no
Content-Type header. In those cases, httr2 returns NA as the
content type.

#166 added a check to make sure the content type is JSON before decoding
the error, however the check did not handle NA values properly and gave
a `missing value where TRUE/FALSE needed`.

This now uses `identical` instead of `==` to compare the content type
string against the expected string.
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