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

If error with zero-length reponse, set error message to "Empty Body" … #116

Closed
wants to merge 1 commit into from

Conversation

gadenbuie
Copy link
Contributor

@gadenbuie gadenbuie commented Jun 14, 2020

…so that correct error is thrown. This is common with conditional requests where a 304 error is returned with an empty body to indicate that the resource hasn't been modified.

Currently, gh fails to return the correct error from gh_error() when res is raw(0) (an empty response body).

library(gh)

issue <- "/repos/r-lib/gh/issues/1"
e_first <- gh(issue)
last_modified <- attributes(e_first)$response$`last-modified`

# Conditional request: https://developer.github.com/v3/#conditional-requests
gh(issue, .send_headers = c("If-Modified-Since" = last_modified))
#> Error: $ operator is invalid for atomic vectors

This PR checks if length(res) == 0 and if so initializes res = list(message = "Empty Body").

# With the change from this PR...
gh(issue, .send_headers = c("If-Modified-Since" = last_modified))
#> Error in gh_process_response(raw): 
#> GitHub API error (304): 304 Not Modified
#> Message: Empty Body

I tried to create a test based on the above reprex, but couldn't quickly figure out how to setup httrmock. Hopefully the above reprex is a good start.

@gadenbuie
Copy link
Contributor Author

Rolled into #117

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.

1 participant