-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (32 loc) · 999 Bytes
/
index.js
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
32
33
34
35
36
37
'use strict';
const joi = require('joi');
const errorSchema = joi.object({
message: joi.string().description('A message explaining the error'),
error: joi.string().description('An error message'),
statusCode: joi.number().integer().description('An HTTP status code')
}).meta({className: 'Error'});
const statusErrors = {
400: errorSchema.description('Bad request'),
401: errorSchema.description('Unauthorized'),
403: errorSchema.description('Forbidden'),
404: errorSchema.description('Not found'),
409: errorSchema.description('Conflict'),
500: errorSchema.description('Internal error')
};
module.exports = {
schema: errorSchema,
statuses: statuses => {
if (statuses && statuses.length) {
return statuses.reduce((result, status) => {
if (statusErrors[status]) {
result[status] = statusErrors[status];
}
return result;
}, {});
}
return {
400: statusErrors['400'],
500: statusErrors['500']
};
}
};