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

No error details given when response is an HTTP 422 #50

Open
pirj opened this issue Jul 25, 2016 · 6 comments
Open

No error details given when response is an HTTP 422 #50

pirj opened this issue Jul 25, 2016 · 6 comments
Labels

Comments

@pirj
Copy link

pirj commented Jul 25, 2016

client.domain.create('my_app', {hostname: "mydomain.com"})
Excon::Error::UnprocessableEntity: Expected([200, 201, 202, 204, 206, 304]) <=> Actual(422 Unprocessable Entity)

with curl:

curl -v -n -X POST https://api.heroku.com/apps/$MY_APP/domains -d '{ "hostname": "mydomain.com" }' -H "Content-Type: application/json" -H "Authorization: Bearer $HEROKU_API_TOKEN"
...
< HTTP/1.1 422 status code 422
...
{
  "id":"invalid_params",
  "message":"mydomain.com is currently in use by another app."
}
@jeffects
Copy link

jeffects commented Jul 29, 2016

Yeah, it is unfortunate that the error message isn't being passed but in the meantime, I believe you can retrieve the error message by parsing the response.

begin
  client.domain.create('my_app', {hostname: "mydomain.com"})
rescue Excon::Error::UnprocessableEntity => e
  JSON.parse(e.response.data[:body])
end

Hope that helps!

@pirj
Copy link
Author

pirj commented Aug 1, 2016

Oh, didn't know response is wrapped into exception. That works around the issue, thanks!
Should I leave the ticket open until there's a better option to get the error message.

@geemus
Copy link
Contributor

geemus commented Aug 1, 2016

Yeah, if you leave it open I can see about improving the default messaging. Sorry for the difficulties here, but glad you have a reasonable workaround available.

@djcp djcp self-assigned this Aug 4, 2016
@djcp
Copy link
Contributor

djcp commented Aug 5, 2016

@geemus There are 2 places I could see making this improvement:

  1. in heroics, possibly by rescuing some subset of excon errors and re-raising a heroics specific-error instance, and
  2. In excon, though that seems to be so widely used that I'd be loath to modify how it throws errors.

Thoughts? Other ideas?

@geemus
Copy link
Contributor

geemus commented Aug 5, 2016

Yeah, I was thinking heroics would probably be the right level/place for it.

@geemus geemus added the bug label Jan 18, 2017
@geemus geemus unassigned djcp Jan 18, 2017
@fschwahn
Copy link

It might be a good idea to add such an error response to the example in the README. I wanted to know what happens in case of an error (ie. if an error is raised, or if I have to look at the return value of eg. heroku.dyno.create), and this is not addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants