File tree 3 files changed +28
-0
lines changed
3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,8 @@ StripeError.generate = function(rawStripeError) {
59
59
return new _Error . StripeAPIError ( rawStripeError ) ;
60
60
case 'idempotency_error' :
61
61
return new _Error . StripeIdempotencyError ( rawStripeError ) ;
62
+ case 'invalid_grant' :
63
+ return new _Error . StripeInvalidGrantError ( rawStripeError ) ;
62
64
}
63
65
return new _Error ( 'Generic' , 'Unknown Error' ) ;
64
66
} ;
@@ -73,3 +75,4 @@ _Error.StripeRateLimitError = StripeError.extend({type: 'StripeRateLimitError'})
73
75
_Error . StripeConnectionError = StripeError . extend ( { type : 'StripeConnectionError' } ) ;
74
76
_Error . StripeSignatureVerificationError = StripeError . extend ( { type : 'StripeSignatureVerificationError' } ) ;
75
77
_Error . StripeIdempotencyError = StripeError . extend ( { type : 'StripeIdempotencyError' } ) ;
78
+ _Error . StripeInvalidGrantError = StripeError . extend ( { type : 'StripeInvalidGrantError' } ) ;
Original file line number Diff line number Diff line change @@ -152,6 +152,15 @@ StripeResource.prototype = {
152
152
if ( response . error ) {
153
153
var err ;
154
154
155
+ // Convert OAuth error responses into a standard format
156
+ // so that the rest of the error logic can be shared
157
+ if ( typeof response . error === 'string' ) {
158
+ response . error = {
159
+ type : response . error ,
160
+ message : response . error_description
161
+ }
162
+ }
163
+
155
164
response . error . headers = headers ;
156
165
response . error . statusCode = res . statusCode ;
157
166
response . error . requestId = res . requestId ;
Original file line number Diff line number Diff line change @@ -230,6 +230,22 @@ describe('StripeResource', function() {
230
230
} ) ;
231
231
} ) ;
232
232
233
+ it ( 'should handle OAuth errors gracefully' , function ( done ) {
234
+ nock ( 'https://connect.stripe.com' )
235
+ . post ( '/oauth/token' )
236
+ . reply ( 400 , {
237
+ error : 'invalid_grant' ,
238
+ error_description : 'This authorization code has already been used. All tokens issued with this code have been revoked.'
239
+ } ) ;
240
+
241
+ realStripe . setMaxNetworkRetries ( 1 ) ;
242
+
243
+ realStripe . oauth . token ( options . data , function ( err ) {
244
+ expect ( err . type ) . to . equal ( 'StripeInvalidGrantError' ) ;
245
+ done ( ) ;
246
+ } ) ;
247
+ } ) ;
248
+
233
249
it ( 'should retry on a 503 error when the method is POST' , function ( done ) {
234
250
nock ( 'https://' + options . host )
235
251
. post ( options . path , options . params )
You can’t perform that action at this time.
0 commit comments