kr / hk

Fast Heroku client
https://hk.heroku.com/
77 stars 6 forks source link

expose ID and message from API errors #52

Open bgentry opened 11 years ago

bgentry commented 11 years ago

Per the v3 API docs, failing requests are returned error messages like the following:

{
  "id":       "rate_limit",
  "message":  "Your account reached the API rate limit\nPlease wait a few minutes before making new requests"
}

However, when a command fails, the output from hk looks like this:

$ hk run -a canary-go bash
Unexpected error: 422 Unprocessable Entity

I'm thinking that there should be a way to expose those error fields in the output. Even if it's not the default, it would make it easier to develop the client if those fields were available by default.

Any thoughts on how to do that? A key=val format feels unnatural here:

Unexpected error: status="422 Unprocessable Entity" id="rate_limit" message="Your account reached the API rate limit\nPlease wait a few minutes before making new requests"

as does a :-separated list:

Unexpected error: status: 422 Unprocessable Entity, id: rate_limit, message: Your account reached the API rate limit\nPlease wait a few minutes before making new requests

Ugh, line breaks in API error messages :rage:

bgentry commented 11 years ago

Also thinking that a --debug flag or similar env that shows request / response body might be helpful.

kr commented 11 years ago

Field message is designed for showing to the user, so we should start by printing it as-is on stderr. We can also recognize the value of field id if we think we can do better than the provided message. And as a last resort (if we don't know the id and there's no provided message) we can do what we currently do as well as printing out the raw response body.