hk icon indicating copy to clipboard operation
hk copied to clipboard

expose ID and message from API errors

Open bgentry opened this issue 12 years ago • 2 comments

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 avatar Aug 28 '13 04:08 bgentry

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

bgentry avatar Aug 28 '13 15:08 bgentry

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.

kr avatar Sep 02 '13 17:09 kr