Merge pull request #154 from mozilla/151-500-errors
fix(server): prevent null exception when oauth server is down
This commit is contained in:
Коммит
1fde0f2d5c
|
@ -57,8 +57,8 @@ exports.create = function createServer() {
|
|||
token: token
|
||||
}
|
||||
}, function(err, resp, body) {
|
||||
if (err) {
|
||||
logger.error('auth', err);
|
||||
if (err || resp.statusCode >= 500) {
|
||||
err = err || resp.statusMessage || 'unknown';
|
||||
return reply(AppError.oauthError(err));
|
||||
}
|
||||
if (body.code >= 400) {
|
||||
|
|
20
test/api.js
20
test/api.js
|
@ -109,6 +109,26 @@ describe('/profile', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should handle oauth server failure', function() {
|
||||
mock.tokenFailure();
|
||||
|
||||
mock.log('server', function(rec) {
|
||||
return rec.levelname === 'ERROR'
|
||||
&& rec.args[0] === 'summary'
|
||||
&& rec.args[1].path === '/v1/profile';
|
||||
});
|
||||
|
||||
return Server.api.get({
|
||||
url: '/profile',
|
||||
headers: {
|
||||
authorization: 'Bearer ' + tok
|
||||
}
|
||||
}).then(function(res) {
|
||||
assert.equal(res.statusCode, 503);
|
||||
assert.equal(res.result.errno, 104);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an avatar if selected', function() {
|
||||
mock.token({
|
||||
user: user,
|
||||
|
|
|
@ -126,6 +126,14 @@ module.exports = function mock(options) {
|
|||
.reply(200, JSON.stringify(tok));
|
||||
},
|
||||
|
||||
tokenFailure: function tokenFailure() {
|
||||
var parts = url.parse(config.get('oauth.url'));
|
||||
return nock(parts.protocol + '//' + parts.host)
|
||||
.post(parts.path + '/verify')
|
||||
.reply(500);
|
||||
|
||||
},
|
||||
|
||||
workerFailure: function workerFailure(action) {
|
||||
if (action !== 'post' && action !== 'delete') {
|
||||
throw new Error('failure must be post or delete');
|
||||
|
|
Загрузка…
Ссылка в новой задаче