mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-12 16:52:50 +00:00
don't reauthenticate on HTTP 400 errors
since these are likely unrelated to authentication issues, but rather have to do with generic API errors or outages
This commit is contained in:
@@ -524,8 +524,8 @@ function updateRtree(item, replace) {
|
||||
function wrapcb(thisArg, callback, cid) {
|
||||
return function(err, result) {
|
||||
if (err) {
|
||||
// 400 Bad Request, 401 Unauthorized, 403 Forbidden..
|
||||
if (err.status === 400 || err.status === 401 || err.status === 403) {
|
||||
// 401 Unauthorized, 403 Forbidden
|
||||
if (err.status === 401 || err.status === 403) {
|
||||
thisArg.logout();
|
||||
}
|
||||
return callback.call(thisArg, err);
|
||||
@@ -642,23 +642,21 @@ export default {
|
||||
|
||||
var isAuthenticated = that.authenticated();
|
||||
|
||||
// 400 Bad Request, 401 Unauthorized, 403 Forbidden
|
||||
// Logout and retry the request..
|
||||
// 401 Unauthorized, 403 Forbidden
|
||||
// Logout and retry the request.
|
||||
if (isAuthenticated && err && err.status &&
|
||||
(err.status === 400 || err.status === 401 || err.status === 403)) {
|
||||
(err.status === 401 || err.status === 403)) {
|
||||
that.logout();
|
||||
that.loadFromAPI(path, callback, options);
|
||||
|
||||
// else, no retry..
|
||||
// else, no retry.
|
||||
} else {
|
||||
// 509 Bandwidth Limit Exceeded, 429 Too Many Requests
|
||||
// Set the rateLimitError flag and trigger a warning..
|
||||
// Set the rateLimitError flag and trigger a warning.
|
||||
if (!isAuthenticated && !_rateLimitError && err && err.status &&
|
||||
(err.status === 509 || err.status === 429)) {
|
||||
_rateLimitError = err;
|
||||
dispatch.call('change');
|
||||
that.reloadApiStatus();
|
||||
|
||||
} else if ((err && _cachedApiStatus === 'online') ||
|
||||
(!err && _cachedApiStatus !== 'online')) {
|
||||
// If the response's error state doesn't match the status,
|
||||
|
||||
@@ -163,14 +163,14 @@ describe('iD.serviceOsm', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('retries an authenticated call unauthenticated if 400 Bad Request', function (done) {
|
||||
it('retries an authenticated call unauthenticated if 401 Unauthorized', function (done) {
|
||||
fetchMock.mock('https://www.openstreetmap.org' + path, {
|
||||
body: response,
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
serverXHR.respondWith('GET', 'https://www.openstreetmap.org' + path,
|
||||
[400, { 'Content-Type': 'text/plain' }, 'Bad Request']);
|
||||
[401, { 'Content-Type': 'text/plain' }, 'Unauthorized']);
|
||||
|
||||
login();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user