sboysel / fredr

An R client for the Federal Reserve Economic Data (FRED) API
https://sboysel.github.io/fredr/
Other
92 stars 21 forks source link

Fix error message being blank #97

Closed SamuelLeeD closed 3 years ago

SamuelLeeD commented 3 years ago

Right now httr::content(resp) doesn't return a vector, so trying to access the error_code and error_message columns from err doesn't do anything and gives an empty error message. Using httr::http_status(resp) works quite neatly, showing both the status code and error message correctly.

DavisVaughan commented 3 years ago

@SamuelLeeD I think for the normal case, we can give a better error message by returning what is in error_message.

For example, here is http_status() vs the message we can give by checking the error_message ("The series does not exist" is quite nice to tell the user)

Browse[2]> httr::http_status(response)
$category
[1] "Client error"

$reason
[1] "Bad Request"

$message
[1] "Client error: (400) Bad Request"

Browse[2]> message
[1] "400: Bad Request.  The series does not exist."

However, I do think that we can use http_status() if it is an "unknown" error format. I'll add that to #98