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
Annotated assertions in stop_for_status #302
Comments
I think the ideal solution would be something like: generate_report(foo, bar, "my_data")
## HTTP Failure: download spreadsheet failure (401: permission denied) But unfortunately "Error: " is hard-coded in C. I don't think "assertion statement" is quite the right term, but I get where you're coming from. I think you want to state what the goal is, and then httr should incorporate that into the message: stop_for_status(req)
# Error: Request failed (HTTP 404: file not found)
stop_for_status(req, goal = "Downloading spreadsheet")
# Error: Downloading spreadsheet failed (HTTP 404: file not found) It's just a matter of getting the English phrasing right so it doesn't feel too awkward. I feel like just tacking "failed" on to the end is suboptimal - i.e. you want
But the default isn't quite right - the request was issued successfully, just the response wasn't as you'd hoped. |
I like the Just to throw out other phrasing ideas:
If you wanted to be more complicated, you could distinguish between the 4xx and 5xx codes -
maybe a default for stop_for_status(req)
# Error: Client failed to complete requested task (HTTP 404: file not found)
stop_for_status(req, goal = "download spreadsheet")
# Error: Client failed to download spreadsheet (HTTP 404: file not found) |
How about this: stop_for_status(req)
# Error: File not found (HTTP 404).
stop_for_status(req, task = "download spreadsheet")
# Error: File not found (HTTP 404). Failed to download spreadsheet. |
Looks good |
Copy from comment.
It makes more readable code if the annotation in
stop_for_status
is not an error message but an assertion statement. When writing code we don't know the error, we only know what it was that we were trying to do in the request. For example:or:
or:
Sorry for not being more clear about this. I think the current implementation
stop_for_status(x, "Spreadsheet not found")
is often impractical because typically we can't know the exact error cause in advance. If we do have a mapping between status code and error messages, we are better of usinghttp_condition
.The goal of
stop_for_status
messages would be to encourage authors of client libraries to let the user know what/where an error was created. Generic http errors messages are not too helpful for high level wrappers:Instead, the user would see a more informative message that states what exactly what went wrong:
The text was updated successfully, but these errors were encountered: