@@ -524,10 +524,6 @@ function updateRtree(item, replace) {
524
524
function wrapcb ( thisArg , callback , cid ) {
525
525
return function ( err , result ) {
526
526
if ( err ) {
527
- // 401 Unauthorized, 403 Forbidden
528
- if ( err . status === 401 || err . status === 403 ) {
529
- thisArg . logout ( ) ;
530
- }
531
527
return callback . call ( thisArg , err ) ;
532
528
533
529
} else if ( thisArg . getConnectionId ( ) !== cid ) {
@@ -640,39 +636,23 @@ export default {
640
636
return ;
641
637
}
642
638
643
- var isAuthenticated = that . authenticated ( ) ;
644
-
645
- // 401 Unauthorized, 403 Forbidden
646
- // Logout and retry the request.
647
- if ( isAuthenticated && err && err . status &&
648
- ( err . status === 401 || err . status === 403 ) ) {
649
- that . logout ( ) ;
650
- that . loadFromAPI ( path , callback , options ) ;
651
- // else, no retry.
652
- } else {
653
- // 509 Bandwidth Limit Exceeded, 429 Too Many Requests
654
- // Set the rateLimitError flag and trigger a warning.
655
- if ( ! isAuthenticated && ! _rateLimitError && err && err . status &&
656
- ( err . status === 509 || err . status === 429 ) ) {
657
- _rateLimitError = err ;
658
- dispatch . call ( 'change' ) ;
659
- that . reloadApiStatus ( ) ;
660
- } else if ( ( err && _cachedApiStatus === 'online' ) ||
661
- ( ! err && _cachedApiStatus !== 'online' ) ) {
662
- // If the response's error state doesn't match the status,
663
- // it's likely we lost or gained the connection so reload the status
664
- that . reloadApiStatus ( ) ;
665
- }
639
+ if ( ( err && _cachedApiStatus === 'online' ) ||
640
+ ( ! err && _cachedApiStatus !== 'online' ) ) {
641
+ // If the response's error state doesn't match the status,
642
+ // it's likely we lost or gained the connection so reload the status
643
+ that . reloadApiStatus ( ) ;
644
+ }
666
645
667
- if ( callback ) {
668
- if ( err ) {
669
- return callback ( err ) ;
646
+ if ( callback ) {
647
+ if ( err ) {
648
+ // eslint-disable-next-line no-console
649
+ console . error ( 'API error:' , err ) ;
650
+ return callback ( err ) ;
651
+ } else {
652
+ if ( path . indexOf ( '.json' ) !== - 1 ) {
653
+ return parseJSON ( payload , callback , options ) ;
670
654
} else {
671
- if ( path . indexOf ( '.json' ) !== - 1 ) {
672
- return parseJSON ( payload , callback , options ) ;
673
- } else {
674
- return parseXML ( payload , callback , options ) ;
675
- }
655
+ return parseXML ( payload , callback , options ) ;
676
656
}
677
657
}
678
658
}
@@ -1098,6 +1078,12 @@ export default {
1098
1078
var hadRequests = hasInflightRequests ( _tileCache ) ;
1099
1079
abortUnwantedRequests ( _tileCache , tiles ) ;
1100
1080
if ( hadRequests && ! hasInflightRequests ( _tileCache ) ) {
1081
+ if ( _rateLimitError ) {
1082
+ // was rate limited, but has settled
1083
+ _rateLimitError = undefined ;
1084
+ dispatch . call ( 'change' ) ;
1085
+ this . reloadApiStatus ( ) ;
1086
+ }
1101
1087
dispatch . call ( 'loaded' ) ; // stop the spinner
1102
1088
}
1103
1089
@@ -1123,23 +1109,43 @@ export default {
1123
1109
1124
1110
_tileCache . inflight [ tile . id ] = this . loadFromAPI (
1125
1111
path + tile . extent . toParam ( ) ,
1126
- tileCallback ,
1112
+ tileCallback . bind ( this ) ,
1127
1113
options
1128
1114
) ;
1129
1115
1130
1116
function tileCallback ( err , parsed ) {
1131
- delete _tileCache . inflight [ tile . id ] ;
1132
1117
if ( ! err ) {
1118
+ delete _tileCache . inflight [ tile . id ] ;
1133
1119
delete _tileCache . toLoad [ tile . id ] ;
1134
1120
_tileCache . loaded [ tile . id ] = true ;
1135
1121
var bbox = tile . extent . bbox ( ) ;
1136
1122
bbox . id = tile . id ;
1137
1123
_tileCache . rtree . insert ( bbox ) ;
1124
+ } else {
1125
+ // map tile loading error: e.g. network connection error,
1126
+ // 509 Bandwidth Limit Exceeded, 429 Too Many Requests
1127
+ if ( ! _rateLimitError && err . status === 509 || err . status === 429 ) {
1128
+ // show "API rate limiting" warning
1129
+ _rateLimitError = err ;
1130
+ dispatch . call ( 'change' ) ;
1131
+ this . reloadApiStatus ( ) ;
1132
+ }
1133
+ setTimeout ( ( ) => {
1134
+ // retry loading the tiles
1135
+ delete _tileCache . inflight [ tile . id ] ;
1136
+ this . loadTile ( tile , callback ) ;
1137
+ } , 8000 ) ;
1138
1138
}
1139
1139
if ( callback ) {
1140
1140
callback ( err , Object . assign ( { data : parsed } , tile ) ) ;
1141
1141
}
1142
1142
if ( ! hasInflightRequests ( _tileCache ) ) {
1143
+ if ( _rateLimitError ) {
1144
+ // was rate limited, but has settled
1145
+ _rateLimitError = undefined ;
1146
+ dispatch . call ( 'change' ) ;
1147
+ this . reloadApiStatus ( ) ;
1148
+ }
1143
1149
dispatch . call ( 'loaded' ) ; // stop the spinner
1144
1150
}
1145
1151
}
0 commit comments