Родитель
0dedad2e50
Коммит
3bd6b14d29
|
@ -2,6 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const AppError = require('./error');
|
||||
const logger = require('./logging')('batch');
|
||||
const P = require('./promise');
|
||||
|
||||
|
@ -35,13 +36,14 @@ function batch(request, map) {
|
|||
return res.result[prop];
|
||||
case 403:
|
||||
case 404:
|
||||
logger.debug('batch.' + res.statusCode, {
|
||||
logger.debug(prop + '.' + res.statusCode, {
|
||||
scope: request.auth.credentials.scope,
|
||||
response: res.result
|
||||
});
|
||||
return undefined;
|
||||
default:
|
||||
throw res.result;
|
||||
logger.error(prop + '.' + res.statusCode, res.result);
|
||||
throw AppError.from(res.result);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -47,6 +47,12 @@ AppError.prototype.header = function (name, value) {
|
|||
this.output.headers[name] = value;
|
||||
};
|
||||
|
||||
AppError.from = function from(obj) {
|
||||
var err = new AppError(obj);
|
||||
err.cause = obj.cause;
|
||||
return err;
|
||||
};
|
||||
|
||||
AppError.translate = function translate(response) {
|
||||
if (response instanceof AppError) {
|
||||
return response;
|
||||
|
@ -126,7 +132,7 @@ AppError.oauthError = function oauthError(err) {
|
|||
code: 503,
|
||||
error: 'Service Unavailable',
|
||||
errno: 104,
|
||||
message: 'OAuth server unavailable'
|
||||
message: 'OAuth server error'
|
||||
}, {
|
||||
cause: err
|
||||
});
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
const Joi = require('joi');
|
||||
|
||||
const AppError = require('../error');
|
||||
|
||||
module.exports = {
|
||||
auth: {
|
||||
strategy: 'oauth',
|
||||
|
@ -15,9 +17,14 @@ module.exports = {
|
|||
}
|
||||
},
|
||||
handler: function email(req, reply) {
|
||||
reply({
|
||||
email: req.auth.credentials.email
|
||||
});
|
||||
var email = req.auth.credentials.email;
|
||||
if (email) {
|
||||
reply({
|
||||
email: email
|
||||
});
|
||||
} else {
|
||||
reply(new AppError.oauthError('email field missing from oauth response'));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -226,7 +226,7 @@
|
|||
},
|
||||
"fxa-notifier-aws": {
|
||||
"version": "1.0.0",
|
||||
"from": "fxa-notifier-aws@*",
|
||||
"from": "fxa-notifier-aws@>=1.0.0 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fxa-notifier-aws/-/fxa-notifier-aws-1.0.0.tgz"
|
||||
},
|
||||
"gm": {
|
||||
|
@ -2087,58 +2087,57 @@
|
|||
"resolved": "https://registry.npmjs.org/mocha-text-cov/-/mocha-text-cov-0.1.0.tgz"
|
||||
},
|
||||
"mozlog": {
|
||||
"version": "2.0.1",
|
||||
"from": "mozlog@>=2.0.0 <2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/mozlog/-/mozlog-2.0.1.tgz",
|
||||
"version": "2.0.0",
|
||||
"from": "mozlog@2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/mozlog/-/mozlog-2.0.0.tgz",
|
||||
"dependencies": {
|
||||
"intel": {
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"from": "intel@>=1.0.0 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/intel/-/intel-1.0.0.tgz",
|
||||
"dependencies": {
|
||||
"chalk": {
|
||||
"version": "0.5.1",
|
||||
"from": "chalk@>=0.5.1 <0.6.0",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-0.5.1.tgz",
|
||||
"version": "1.1.0",
|
||||
"from": "chalk@>=1.1.0 <1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.0.tgz",
|
||||
"dependencies": {
|
||||
"ansi-styles": {
|
||||
"version": "1.1.0",
|
||||
"from": "ansi-styles@>=1.1.0 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-1.1.0.tgz"
|
||||
"version": "2.1.0",
|
||||
"from": "ansi-styles@>=2.1.0 <3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.1.0.tgz"
|
||||
},
|
||||
"escape-string-regexp": {
|
||||
"version": "1.0.3",
|
||||
"from": "escape-string-regexp@>=1.0.0 <2.0.0",
|
||||
"from": "escape-string-regexp@>=1.0.2 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.3.tgz"
|
||||
},
|
||||
"has-ansi": {
|
||||
"version": "0.1.0",
|
||||
"from": "has-ansi@>=0.1.0 <0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-0.1.0.tgz",
|
||||
"version": "2.0.0",
|
||||
"from": "has-ansi@>=2.0.0 <3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz",
|
||||
"dependencies": {
|
||||
"ansi-regex": {
|
||||
"version": "0.2.1",
|
||||
"from": "ansi-regex@>=0.2.0 <0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-0.2.1.tgz"
|
||||
"version": "2.0.0",
|
||||
"from": "ansi-regex@>=2.0.0 <3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.0.0.tgz"
|
||||
}
|
||||
}
|
||||
},
|
||||
"strip-ansi": {
|
||||
"version": "0.3.0",
|
||||
"from": "strip-ansi@>=0.3.0 <0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-0.3.0.tgz",
|
||||
"version": "3.0.0",
|
||||
"from": "strip-ansi@>=3.0.0 <4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.0.tgz",
|
||||
"dependencies": {
|
||||
"ansi-regex": {
|
||||
"version": "0.2.1",
|
||||
"from": "ansi-regex@>=0.2.0 <0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-0.2.1.tgz"
|
||||
"version": "2.0.0",
|
||||
"from": "ansi-regex@>=2.0.0 <3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.0.0.tgz"
|
||||
}
|
||||
}
|
||||
},
|
||||
"supports-color": {
|
||||
"version": "0.2.0",
|
||||
"from": "supports-color@>=0.2.0 <0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-0.2.0.tgz"
|
||||
"version": "2.0.0",
|
||||
"from": "supports-color@>=2.0.0 <3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -2153,9 +2152,9 @@
|
|||
"resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.9.tgz"
|
||||
},
|
||||
"strftime": {
|
||||
"version": "0.8.4",
|
||||
"from": "strftime@>=0.8.2 <0.9.0",
|
||||
"resolved": "https://registry.npmjs.org/strftime/-/strftime-0.8.4.tgz"
|
||||
"version": "0.9.2",
|
||||
"from": "strftime@>=0.9.2 <0.10.0",
|
||||
"resolved": "https://registry.npmjs.org/strftime/-/strftime-0.9.2.tgz"
|
||||
},
|
||||
"symbol": {
|
||||
"version": "0.2.1",
|
||||
|
|
35
test/api.js
35
test/api.js
|
@ -74,6 +74,41 @@ describe('/profile', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should handle oauth errors', function() {
|
||||
mock.token({
|
||||
user: USERID,
|
||||
scope: ['profile:write']
|
||||
// intentionally left off email
|
||||
});
|
||||
|
||||
mock.log('server', function(rec) {
|
||||
return rec.levelname === 'ERROR'
|
||||
&& rec.args[0] === 'summary'
|
||||
&& rec.args[1].path === '/v1/email';
|
||||
});
|
||||
|
||||
mock.log('batch', function(rec) {
|
||||
return rec.levelname === 'ERROR'
|
||||
&& rec.args[0] === 'email.503';
|
||||
});
|
||||
|
||||
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,
|
||||
|
|
|
@ -21,7 +21,7 @@ const SIZES = require('../../lib/img').SIZES;
|
|||
|
||||
module.exports = function mock(options) {
|
||||
assert(options.userid);
|
||||
var TOKEN_GOOD = JSON.stringify({
|
||||
const TOKEN_GOOD = JSON.stringify({
|
||||
user: options.userid,
|
||||
scope: ['profile'],
|
||||
email: 'user@example.domain'
|
||||
|
|
Загрузка…
Ссылка в новой задаче