-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (28 loc) · 726 Bytes
/
index.js
File metadata and controls
31 lines (28 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"use strict";
/**
internal factory
@param {string} - the error message that will be caught by API gateway regex
@param {number} - html error code
@return {function}
*/
function errorFactory (error, status) {
/**
exported function
This function optionnally injects and object into the error response
@param {Object}
@return {string}
*/
return function error (obj) {
return JSON.stringify(Object.assign({
error: error,
status: status
}, obj));
};
}
module.exports = {
badRequest: errorFactory("Bad Request", 400),
unauthorized: errorFactory("Unauthorized", 401),
forbidden: errorFactory("Forbidden", 403),
notFound: errorFactory("Not Found", 404),
internal: errorFactory("Internal Server Error", 500)
}