bchavez / Coinbase

:moneybag: A .NET/C# implementation of the Coinbase API.

Home Page:https://developers.coinbase.com/api/v2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error Handling should occur internally

granthoff1107 opened this issue · comments

This relates to Issue #33. I made a mistake in say that AllowAnyHttpStatus should be allowed.
When Making a request to an api endpoint, if the request succeeds the end user won't have anyway of knowing with out manually checking if there are errors.

    //pseudo
    var transactions = await client.Transactions.GetListAsync();
    if(false == transactions.Data.Any())
    {
          Print("No Transactions")
    }

This would be bad because if the user forgets to check the error like above, the application would be under the impression that you have no transactions, when in reality their could be an error/

Ideally we can implement an internal error handler which will parse the Errors json and throw an appropriate exception based on the error code e.g if the error Id = invalid_scope. the user would know to make its oauth request with the proper scopes next time.

This seems like a larger change so perhaps it might make sense to create a dummy global exception handler, e.g

    public CoinbaseApiException(Error[] errors) : Exception
    {
          Error[] errors
          public CoinbaseApiException(errors)
          {
             this.errors = errors;
          }
    } 

The JsonResponse type has a .HasError() method you can use to check if errors occurred.

var transactions = await client.Transactions.GetListAsync();
if( transactions.HasError() )
{
     //we have some errors to take care of.
}

In this case, W.R.T. API aesthetics, I prefer having to explicitly check for errors instead of the relying on the underlying exception mechanism as a means for decision making. Maybe we can make this more clear in the README?

Yeah, that makes sense.
I just came across this in my code and realized I forgot to check for errors.
I haven't found any bugs in the beta everything working smoothly.
Today I've pretty much been raising more feature requests, but I pretty much have everything integrated and everything seems to be working smoothly.

Thanks for releasing the beta when you did, its save me a lot of time.

That's great, I'm happy to hear everything is working smoothly. Seems like we're close to removing the beta and tag a formal release. I think we should let it bake for a few more days before we pull the trigger.

If you want to send a PR for the README where we make checking .HasError() more explicit, I'd be happy to accept.

Thanks,
Brian