BrandonRomano / wrecker

A golang request builder for JSON APIs
MIT License
24 stars 0 forks source link

Improve Error Handling #29

Open benpate opened 9 years ago

benpate commented 9 years ago

When we get a REST error from a remote server, it often includes a JSON package containing a description of the error, which is usually a very different JSON schema than a successful transaction. In this case, it would be nice to be able to unmarshal that information into another variable that is looking for those error values.

Because of wreckers chaining API, this seems like it would be a really great progressive enhancement:

w := wrecker.New("http://www.awesome.com").
    Get("/service/name").
    Into(&result).
    Error(&error).
    Execute()

What do you think?

benpate commented 9 years ago

In addition, I think we should bubble up some common HTTP errors into the err return value. For instance, if we get an HTTP 500 error from the server, then err should not come back null.

BrandonRomano commented 9 years ago

Hey @benpate -- yeah this is a great idea.

I've never run into this use case myself, as all of the API's I deal with have the same JSON schema for the error / non error state (usually there's an object for an error, and it's just set to null on success).

But, this is definitely not always the case.

I'm going to try to chunk out some time tonight + tackle this!

benpate commented 9 years ago

Great. This will be a huge addition -- especially for APIs that use HTTP status codes to report errors, like most of the ones I'm working to integrate. Right now, I'm basically getting a successful response and then empty data. It's sooo frustrating to troubleshoot X(