@@ -1326,6 +1326,36 @@ Raven.prototype = {
1326
1326
return this . _backoffDuration && now ( ) - this . _backoffStart < this . _backoffDuration ;
1327
1327
} ,
1328
1328
1329
+ _setBackoffState : function ( request ) {
1330
+ // if we are already in a backoff state, don't change anything
1331
+ if ( this . _shouldBackoff ( ) )
1332
+ return ;
1333
+
1334
+ var status = request . status ;
1335
+
1336
+ // 400 - project_id doesn't exist or some other fatal
1337
+ // 401 - nvalid/revoked dsn
1338
+ // 429 - too many requests
1339
+ if ( ! ( status === 400 || status === 401 || status === 429 ) )
1340
+ return ;
1341
+
1342
+ var retry ;
1343
+ try {
1344
+ // If Retry-After is not in Access-Control-Allow-Headers, most
1345
+ // browsers will throw an exception trying to access it
1346
+ retry = request . getResponseHeader ( 'Retry-After' ) ;
1347
+ retry = parseInt ( retry , 10 ) ;
1348
+ } catch ( e ) {
1349
+ /* eslint no-empty:0 */
1350
+ }
1351
+
1352
+ this . _backoffDuration = retry
1353
+ ? retry
1354
+ : this . _backoffDuration * 2 || 1000 ;
1355
+
1356
+ this . _backoffStart = now ( ) ;
1357
+ } ,
1358
+
1329
1359
_send : function ( data ) {
1330
1360
if ( this . _shouldBackoff ( ) ) {
1331
1361
return ;
@@ -1453,10 +1483,8 @@ Raven.prototype = {
1453
1483
callback && callback ( ) ;
1454
1484
} ,
1455
1485
onError : function failure ( error ) {
1456
- // too many requests
1457
- if ( ! self . _shouldBackoff ( ) && error . request && error . request . status === 429 ) {
1458
- self . _backoffDuration = self . _backoffDuration * 2 || 1000 ;
1459
- self . _backoffStart = now ( ) ;
1486
+ if ( error . request ) {
1487
+ self . _setBackoffState ( error . request ) ;
1460
1488
}
1461
1489
1462
1490
self . _triggerEvent ( 'failure' , {
0 commit comments