#303: do not logout if token refresh failed due to 5xx error

This commit is contained in:
SleepWalker 2017-02-26 11:58:33 +02:00
parent 4074a65329
commit 1c467bc7bd
2 changed files with 27 additions and 8 deletions

View File

@ -68,16 +68,19 @@ export default function refreshTokenMiddleware({dispatch, getState}) {
}
function requestAccessToken(refreshToken, dispatch) {
let promise;
if (refreshToken) {
promise = authentication.requestToken(refreshToken);
} else {
promise = Promise.reject();
return authentication.requestToken(refreshToken)
.then(({token}) => dispatch(updateToken(token)))
.catch((resp = {}) => {
if (resp.originalResponse && resp.originalResponse.status >= 500) {
return Promise.reject(resp);
}
return dispatch(logoutAll());
});
}
return promise
.then(({token}) => dispatch(updateToken(token)))
.catch(() => dispatch(logoutAll()));
return dispatch(logoutAll());
}

View File

@ -110,7 +110,7 @@ describe('refreshTokenMiddleware', () => {
);
});
it('should if token can not be parsed', () => {
it('should logout if token can not be parsed', () => {
const account = {
token: 'realy bad token',
refreshToken
@ -143,6 +143,22 @@ describe('refreshTokenMiddleware', () => {
])
);
});
it('should not logout if request failed with 5xx', () => {
const resp = {
originalResponse: {
status: 500
}
};
authentication.requestToken.returns(Promise.reject(resp));
return expect(middleware.before({url: 'foo', options: {}}), 'to be rejected with', resp).then(() =>
expect(dispatch, 'to have no calls satisfying', [
{payload: {isGuest: true}}
])
);
});
});
it('should not be applied if no token', () => {