Skip to content

Commit 850a4ff

Browse files
committed
fix(style): eslint errorHandler.js
1 parent b6eb6dd commit 850a4ff

File tree

1 file changed

+40
-41
lines changed

1 file changed

+40
-41
lines changed

lib/errorHandler.js

+40-41
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
'use strict';
2-
/* globals module */
32

4-
var translator = require.main.require('./src/translator'),
5-
isLanguageKey = /^\[\[[\w.\-_:]+]]$/,
3+
var translator = require.main.require('./src/translator');
4+
var isLanguageKey = /^\[\[[\w.\-_:]+]]$/;
65

7-
ErrorHandler = {};
6+
var ErrorHandler = {};
87

9-
ErrorHandler.respond = function(status, res) {
8+
ErrorHandler.respond = function (status, res) {
109
var errorPayload = ErrorHandler.generate(status);
1110

1211
res.status(status).json(errorPayload);
1312
return true;
1413
};
1514

16-
ErrorHandler.handle = function(err, res, payload) {
15+
ErrorHandler.handle = function (err, res, payload) {
1716
if (err) {
1817
if (isLanguageKey.test(err.message)) {
19-
translator.translate(err.message, 'en-GB', function(translated) {
18+
translator.translate(err.message, 'en-GB', function (translated) {
2019
res.status(400).json(ErrorHandler.generate(400, undefined, translated));
2120
});
2221
} else {
@@ -25,12 +24,12 @@ ErrorHandler.handle = function(err, res, payload) {
2524
} else {
2625
res.status(200).json({
2726
code: 'ok',
28-
payload: payload || {}
27+
payload: payload || {},
2928
});
3029
}
3130
};
3231

33-
ErrorHandler.generate = function(status, code, message, params) {
32+
ErrorHandler.generate = function (status, code, message, params) {
3433
// All arguments are optional
3534
var errorPayload = ErrorHandler.statusToCode(status);
3635

@@ -41,41 +40,41 @@ ErrorHandler.generate = function(status, code, message, params) {
4140
return errorPayload;
4241
};
4342

44-
ErrorHandler.statusToCode = function(status) {
43+
ErrorHandler.statusToCode = function (status) {
4544
var payload = {
46-
code: 'internal-server-error',
47-
message: 'An unexpected error was encountered while attempting to service your request.',
48-
params: {}
49-
};
50-
51-
switch(status) {
52-
case 400:
53-
payload.code = 'bad-request';
54-
payload.message = 'Something was wrong with the request payload you passed in.';
55-
break;
56-
57-
case 401:
58-
payload.code = 'not-authorised';
59-
payload.message = 'A valid login session was not found. Please log in and try again.';
60-
break;
61-
62-
case 403:
63-
payload.code = 'forbidden';
64-
payload.message = 'You are not authorised to make this call';
65-
break;
66-
67-
case 404:
68-
payload.code = 'not-found';
69-
payload.message = 'Invalid API call';
70-
break;
71-
72-
case 426:
73-
payload.code = 'upgrade-required';
74-
payload.message = 'HTTPS is required for requests to the write api, please re-send your request via HTTPS';
75-
break;
45+
code: 'internal-server-error',
46+
message: 'An unexpected error was encountered while attempting to service your request.',
47+
params: {},
48+
};
49+
50+
switch (status) {
51+
case 400:
52+
payload.code = 'bad-request';
53+
payload.message = 'Something was wrong with the request payload you passed in.';
54+
break;
55+
56+
case 401:
57+
payload.code = 'not-authorised';
58+
payload.message = 'A valid login session was not found. Please log in and try again.';
59+
break;
60+
61+
case 403:
62+
payload.code = 'forbidden';
63+
payload.message = 'You are not authorised to make this call';
64+
break;
65+
66+
case 404:
67+
payload.code = 'not-found';
68+
payload.message = 'Invalid API call';
69+
break;
70+
71+
case 426:
72+
payload.code = 'upgrade-required';
73+
payload.message = 'HTTPS is required for requests to the write api, please re-send your request via HTTPS';
74+
break;
7675
}
7776

7877
return payload;
7978
};
8079

81-
module.exports = ErrorHandler;
80+
module.exports = ErrorHandler;

0 commit comments

Comments
 (0)