interledger / open-payments

Protocol to setup payments between entities on the Web based on GNAP
https://openpayments.dev
Apache License 2.0
204 stars 34 forks source link

Expose error code/response body to `OpenPaymentsClientError` #482

Closed sidvishnoi closed 4 months ago

sidvishnoi commented 4 months ago

Context: Web Monetization extension

If a user revokes key from wallet, all subsequent requests (to auth.rafiki.money in this case) error with HTTP 400 + invalid_client. But this code isn't available to client to check whether it's a 400 due to invalid_client or some other reason. The response body says invalid_client, but we can't access the body on error.

Exposing this (GNAPErrorCode in case of auth server) in OpenPaymentsClientError would help us gracefully handle https://github.com/interledger/web-monetization-extension/issues/332

sidvishnoi commented 4 months ago

Also, would be helpful to have access to error messages from the resource server (like Signature validation error: could not find key in list of client keys in this case)

mkurapov commented 4 months ago

For this, I merged in a PR in rafiki that adds proper GNAP error objects in the auth server:

We will publish a new version of Rafiki (alpha 14) such that the test wallet can be updated with this new change.

In the meantime, I'll edit the client so it can surface up the proper error (for now, the OpenPaymentsClientError will contain code: string that will have invalid_client on those errors).

In my opinion this should be a larger effort to actually add all of the possible error codes to both the AS and the RS specs, so they are obvious to the users of Open Payments :+1: I'll bring it up in the next Open Payments catch up call

sidvishnoi commented 4 months ago

Can possibly include in error description until codes are finalized?

mkurapov commented 4 months ago

Can possibly include in error description until codes are finalized?

In this Open Payments example error:

image

I'd imagine the corresponding OpenPaymentsClientError will be as such:

try {
} catch (err) { 
  err.code  // "invalid_client"
  err.description // "Could not determine client"
}