Paypal-checkout-components: Pass back specific enumerated error codes for known failure cases

Created on 8 Jun 2017  路  11Comments  路  Source: paypal/paypal-checkout-components

Hi guys.

Running checkout.js v4 here...

I'm trying to handle a scenario where a user might not enter the proper credentials or simply have an auth issue... So I force the checkout button to fail by passing a bogus clientID in sandbox, I get the following:

Error: Error: Error: Error: Request to post https://www.sandbox.paypal.com/v1/oauth2/token failed with 401 error

{
"error": "invalid_client",
"error_description": "Client Authentication failed"
}

at XMLHttpRequest.<anonymous> (https://www.paypalobjects.com/api/checkout.js:10997:39)
at Object._RECEIVE_MESSAGE_TYPE.(anonymous function) [as postrobot_message_response] (https://www.paypalobjects.com/api/checkout.js?_=1496936366975:2477:118)
at receiveMessage (https://www.paypalobjects.com/api/checkout.js?_=1496936366975:2381:73)
at messageListener (https://www.paypalobjects.com/api/checkout.js?_=1496936366975:2401:13)
at Object._RECEIVE_MESSAGE_TYPE.(anonymous function) [as postrobot_message_response] (https://www.paypalobjects.com/api/checkout.js:2477:118)
at receiveMessage (https://www.paypalobjects.com/api/checkout.js:2381:73)
at messageListener (https://www.paypalobjects.com/api/checkout.js:2401:13)

at XMLHttpRequest.<anonymous> (https://www.paypalobjects.com/api/checkout.js:10997:39)
at Object._RECEIVE_MESSAGE_TYPE.(anonymous function) [as postrobot_message_response] (https://www.paypalobjects.com/api/checkout.js?_=1496936366975:2477:118)
at receiveMessage (https://www.paypalobjects.com/api/checkout.js?_=1496936366975:2381:73)
at messageListener (https://www.paypalobjects.com/api/checkout.js?_=1496936366975:2401:13)
at Object._RECEIVE_MESSAGE_TYPE.(anonymous function) [as postrobot_message_response] (https://www.paypalobjects.com/api/checkout.js:2477:118)
at receiveMessage (https://www.paypalobjects.com/api/checkout.js:2381:73)
at messageListener (https://www.paypalobjects.com/api/checkout.js:2401:13)
at deserializeError (https://www.paypalobjects.com/api/checkout.js?_=1496936366975:2959:20)
at https://www.paypalobjects.com/api/checkout.js?_=1496936366975:2965:239
at https://www.paypalobjects.com/api/checkout.js?_=1496936366975:3153:30
at each (https://www.paypalobjects.com/api/checkout.js?_=1496936366975:3146:74)
at replaceObject (https://www.paypalobjects.com/api/checkout.js?_=1496936366975:3152:13)
at https://www.paypalobjects.com/api/checkout.js?_=1496936366975:3154:154
at each (https://www.paypalobjects.com/api/checkout.js?_=1496936366975:3146:228)
at replaceObject (https://www.paypalobjects.com/api/checkout.js?_=1496936366975:3152:13)
at https://www.paypalobjects.com/api/checkout.js?_=1496936366975:3154:154
at each (https://www.paypalobjects.com/api/checkout.js?_=1496936366975:3146:228)

Btw I can't parse this response and any other attempt to catch the error in other ways has failed. I'm not sure what to do. Seems odd that this is the contents of onError: function (err) { console.log(err) } in the first place.

Am I missing something?

outdated

All 11 comments

Yeah, right now these errors are designed more to be logged than they are to be consumed/handled by callers.

For most cases, I don't see that changing -- but for specific failures like "invalid client id" it definitely does make sense for us to enumerate these error cases and pass back specific error codes.

I'll keep this open as a feature request.

I'm not looking for enumerated codes, really. More just a consumable error object that isn't buried inside a bunch of other stuff with stack traces...

{
"error": "invalid_client",
"error_description": "Client Authentication failed"
}

EDIT: I indeed can convert the entire response to a string and substring out the contents in brackets, but I'm worried about this breaking in the future of checkout.js because that seems hacky.

Yeah, we're talking about the same thing 馃憤

I agree, I wouldn't recommend trying to parse the error as it stands.

Alright, thanks for the follow-up.

Let's keep this open -- I think it's a good idea.

when it's will be done? checkout.js isn't usable without error messages.

@verysimplenick -- in the mean time, you're free to make a server-side api call to create/execute the payment: https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/server-side-REST-integration/

The client-side integration is designed for simpler sites which just want to plug-and-play. We're planning to pass back error codes from the REST api, but this needs to go through security vetting first.

@bluepnume Ok, how I can get Bearer token from your js client and transfer to my server execute handler?
Or I need create all steps from server?

Afraid not -- you'd need to make each api call from your server, with your client and secret.

In the meantime, what would be a suitable action for onError in a client-side implementation of checkout.js ?

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings