@@ -1326,6 +1326,36 @@ Raven.prototype = {
13261326 return this . _backoffDuration && now ( ) - this . _backoffStart < this . _backoffDuration ;
13271327 } ,
13281328
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+
13291359 _send : function ( data ) {
13301360 if ( this . _shouldBackoff ( ) ) {
13311361 return ;
@@ -1453,10 +1483,8 @@ Raven.prototype = {
14531483 callback && callback ( ) ;
14541484 } ,
14551485 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 ) ;
14601488 }
14611489
14621490 self . _triggerEvent ( 'failure' , {
0 commit comments