@docbrasil/api-systemmanager 1.0.38 → 1.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/admin/doctypes.js +1 -1
- package/api/admin/document.js +1 -1
- package/api/admin/form.js +1 -1
- package/api/admin/list.js +1 -1
- package/api/admin/message.js +1 -1
- package/api/admin/notification.js +1 -1
- package/api/admin/plugin.js +1 -1
- package/api/admin/policy.js +1 -1
- package/api/admin/processes.js +1 -1
- package/api/admin/task.js +1 -1
- package/api/admin/user.js +1 -1
- package/api/general/geoLocation.js +1 -1
- package/api/session.js +1 -1
- package/api/user/document.js +1 -1
- package/api/user/organization.js +1 -1
- package/api/user/process.js +1 -1
- package/api/user/register.js +1 -1
- package/api/user/task.js +1 -1
- package/api/user/user.js +14 -2
- package/api/utils/promises.js +1 -1
- package/helper/boom.js +487 -0
- package/package.json +1 -1
package/api/admin/doctypes.js
CHANGED
package/api/admin/document.js
CHANGED
package/api/admin/form.js
CHANGED
package/api/admin/list.js
CHANGED
package/api/admin/message.js
CHANGED
package/api/admin/plugin.js
CHANGED
package/api/admin/policy.js
CHANGED
package/api/admin/processes.js
CHANGED
package/api/admin/task.js
CHANGED
package/api/admin/user.js
CHANGED
package/api/session.js
CHANGED
package/api/user/document.js
CHANGED
package/api/user/organization.js
CHANGED
package/api/user/process.js
CHANGED
package/api/user/register.js
CHANGED
package/api/user/task.js
CHANGED
package/api/user/user.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const _ = require('lodash');
|
|
2
|
-
const Boom = require('
|
|
2
|
+
const Boom = require('../../helper/boom');
|
|
3
3
|
const Joi = require('joi');
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -137,7 +137,7 @@ class User {
|
|
|
137
137
|
* @param {string} params.secAnswer The security answer
|
|
138
138
|
* @param {string} params.timezone The timezone
|
|
139
139
|
* @param {string} params.userLanguage The user language
|
|
140
|
-
* @param {string} params.changePassword If we need to change the status and we changed the password
|
|
140
|
+
* @param {string} params.changePassword (required) If we need to change the status and we changed the password
|
|
141
141
|
* @param {string} params.acceptTermsOfUse If the user has accepted the terms of change
|
|
142
142
|
* @param {string} session Session, token JWT
|
|
143
143
|
* @return {Promise<void>}
|
|
@@ -157,8 +157,20 @@ class User {
|
|
|
157
157
|
const self = this;
|
|
158
158
|
|
|
159
159
|
try {
|
|
160
|
+
Joi.assert(session, Joi.string().required());
|
|
161
|
+
Joi.assert(params, Joi.object().required());
|
|
162
|
+
Joi.assert(params.changePassword, Joi.boolean().required());
|
|
163
|
+
|
|
160
164
|
if(_.isEmpty(params)) return;
|
|
161
165
|
|
|
166
|
+
const { changePassword = false, password = '' } = params;
|
|
167
|
+
|
|
168
|
+
if(changePassword && password === '') {
|
|
169
|
+
throw new Error('It is required to change the password')
|
|
170
|
+
} else {
|
|
171
|
+
params.changePassword = false;
|
|
172
|
+
}
|
|
173
|
+
|
|
162
174
|
const url = 'users';
|
|
163
175
|
const apiCall = self._client.put(url, params, self._setHeader(session));
|
|
164
176
|
return self._returnData(await apiCall);
|
package/api/utils/promises.js
CHANGED
package/helper/boom.js
ADDED
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
const _ = require('lodash');
|
|
2
|
+
|
|
3
|
+
const Hoek = {
|
|
4
|
+
clone: message => _.clone(message),
|
|
5
|
+
assert: (condition, ...args) => {
|
|
6
|
+
if (condition) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (args.length === 1 &&
|
|
11
|
+
args[0] instanceof Error) {
|
|
12
|
+
|
|
13
|
+
throw args[0];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
throw new Error(args);
|
|
17
|
+
},
|
|
18
|
+
escapeHeaderAttribute: attribute => {
|
|
19
|
+
return attribute.replace(/\\/g, '\\\\').replace(/\"/g, '\\"');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
const internals = {
|
|
25
|
+
codes: new Map([
|
|
26
|
+
[100, 'Continue'],
|
|
27
|
+
[101, 'Switching Protocols'],
|
|
28
|
+
[102, 'Processing'],
|
|
29
|
+
[200, 'OK'],
|
|
30
|
+
[201, 'Created'],
|
|
31
|
+
[202, 'Accepted'],
|
|
32
|
+
[203, 'Non-Authoritative Information'],
|
|
33
|
+
[204, 'No Content'],
|
|
34
|
+
[205, 'Reset Content'],
|
|
35
|
+
[206, 'Partial Content'],
|
|
36
|
+
[207, 'Multi-Status'],
|
|
37
|
+
[300, 'Multiple Choices'],
|
|
38
|
+
[301, 'Moved Permanently'],
|
|
39
|
+
[302, 'Moved Temporarily'],
|
|
40
|
+
[303, 'See Other'],
|
|
41
|
+
[304, 'Not Modified'],
|
|
42
|
+
[305, 'Use Proxy'],
|
|
43
|
+
[307, 'Temporary Redirect'],
|
|
44
|
+
[400, 'Bad Request'],
|
|
45
|
+
[401, 'Unauthorized'],
|
|
46
|
+
[402, 'Payment Required'],
|
|
47
|
+
[403, 'Forbidden'],
|
|
48
|
+
[404, 'Not Found'],
|
|
49
|
+
[405, 'Method Not Allowed'],
|
|
50
|
+
[406, 'Not Acceptable'],
|
|
51
|
+
[407, 'Proxy Authentication Required'],
|
|
52
|
+
[408, 'Request Time-out'],
|
|
53
|
+
[409, 'Conflict'],
|
|
54
|
+
[410, 'Gone'],
|
|
55
|
+
[411, 'Length Required'],
|
|
56
|
+
[412, 'Precondition Failed'],
|
|
57
|
+
[413, 'Request Entity Too Large'],
|
|
58
|
+
[414, 'Request-URI Too Large'],
|
|
59
|
+
[415, 'Unsupported Media Type'],
|
|
60
|
+
[416, 'Requested Range Not Satisfiable'],
|
|
61
|
+
[417, 'Expectation Failed'],
|
|
62
|
+
[418, 'I\'m a teapot'],
|
|
63
|
+
[422, 'Unprocessable Entity'],
|
|
64
|
+
[423, 'Locked'],
|
|
65
|
+
[424, 'Failed Dependency'],
|
|
66
|
+
[425, 'Too Early'],
|
|
67
|
+
[426, 'Upgrade Required'],
|
|
68
|
+
[428, 'Precondition Required'],
|
|
69
|
+
[429, 'Too Many Requests'],
|
|
70
|
+
[431, 'Request Header Fields Too Large'],
|
|
71
|
+
[451, 'Unavailable For Legal Reasons'],
|
|
72
|
+
[500, 'Internal Server Error'],
|
|
73
|
+
[501, 'Not Implemented'],
|
|
74
|
+
[502, 'Bad Gateway'],
|
|
75
|
+
[503, 'Service Unavailable'],
|
|
76
|
+
[504, 'Gateway Time-out'],
|
|
77
|
+
[505, 'HTTP Version Not Supported'],
|
|
78
|
+
[506, 'Variant Also Negotiates'],
|
|
79
|
+
[507, 'Insufficient Storage'],
|
|
80
|
+
[509, 'Bandwidth Limit Exceeded'],
|
|
81
|
+
[510, 'Not Extended'],
|
|
82
|
+
[511, 'Network Authentication Required']
|
|
83
|
+
])
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
exports.Boom = class extends Error {
|
|
88
|
+
|
|
89
|
+
constructor(message, options = {}) {
|
|
90
|
+
|
|
91
|
+
if (message instanceof Error) {
|
|
92
|
+
return exports.boomify(Hoek.clone(message), options);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const { statusCode = 500, data = null, ctor = exports.Boom } = options;
|
|
96
|
+
const error = new Error(message ? message : undefined); // Avoids settings null message
|
|
97
|
+
Error.captureStackTrace(error, ctor); // Filter the stack to our external API
|
|
98
|
+
error.data = data;
|
|
99
|
+
const boom = internals.initialize(error, statusCode);
|
|
100
|
+
|
|
101
|
+
Object.defineProperty(boom, 'typeof', { value: ctor });
|
|
102
|
+
|
|
103
|
+
if (options.decorate) {
|
|
104
|
+
Object.assign(boom, options.decorate);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return boom;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static [Symbol.hasInstance](instance) {
|
|
111
|
+
|
|
112
|
+
if (this === exports.Boom) {
|
|
113
|
+
return exports.isBoom(instance);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Cannot use 'instanceof' as it creates infinite recursion
|
|
117
|
+
|
|
118
|
+
return this.prototype.isPrototypeOf(instance);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
exports.isBoom = function (err, statusCode) {
|
|
124
|
+
|
|
125
|
+
return err instanceof Error && !!err.isBoom && (!statusCode || err.output.statusCode === statusCode);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
exports.boomify = function (err, options) {
|
|
130
|
+
|
|
131
|
+
Hoek.assert(err instanceof Error, 'Cannot wrap non-Error object');
|
|
132
|
+
|
|
133
|
+
options = options || {};
|
|
134
|
+
|
|
135
|
+
if (options.data !== undefined) {
|
|
136
|
+
err.data = options.data;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (options.decorate) {
|
|
140
|
+
Object.assign(err, options.decorate);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (!err.isBoom) {
|
|
144
|
+
return internals.initialize(err, options.statusCode || 500, options.message);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (options.override === false || // Defaults to true
|
|
148
|
+
!options.statusCode && !options.message) {
|
|
149
|
+
|
|
150
|
+
return err;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return internals.initialize(err, options.statusCode || err.output.statusCode, options.message);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
// 4xx Client Errors
|
|
158
|
+
|
|
159
|
+
exports.badRequest = function (message, data) {
|
|
160
|
+
|
|
161
|
+
return new exports.Boom(message, { statusCode: 400, data, ctor: exports.badRequest });
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
exports.unauthorized = function (message, scheme, attributes) { // Or (message, wwwAuthenticate[])
|
|
166
|
+
|
|
167
|
+
const err = new exports.Boom(message, { statusCode: 401, ctor: exports.unauthorized });
|
|
168
|
+
|
|
169
|
+
// function (message)
|
|
170
|
+
|
|
171
|
+
if (!scheme) {
|
|
172
|
+
return err;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// function (message, wwwAuthenticate[])
|
|
176
|
+
|
|
177
|
+
if (typeof scheme !== 'string') {
|
|
178
|
+
err.output.headers['WWW-Authenticate'] = scheme.join(', ');
|
|
179
|
+
return err;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// function (message, scheme, attributes)
|
|
183
|
+
|
|
184
|
+
let wwwAuthenticate = `${scheme}`;
|
|
185
|
+
|
|
186
|
+
if (attributes ||
|
|
187
|
+
message) {
|
|
188
|
+
|
|
189
|
+
err.output.payload.attributes = {};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (attributes) {
|
|
193
|
+
if (typeof attributes === 'string') {
|
|
194
|
+
wwwAuthenticate += ' ' + Hoek.escapeHeaderAttribute(attributes);
|
|
195
|
+
err.output.payload.attributes = attributes;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
wwwAuthenticate += ' ' + Object.keys(attributes).map((name) => {
|
|
199
|
+
|
|
200
|
+
let value = attributes[name];
|
|
201
|
+
if (value === null ||
|
|
202
|
+
value === undefined) {
|
|
203
|
+
|
|
204
|
+
value = '';
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
err.output.payload.attributes[name] = value;
|
|
208
|
+
return `${name}="${Hoek.escapeHeaderAttribute(value.toString())}"`;
|
|
209
|
+
})
|
|
210
|
+
.join(', ');
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (message) {
|
|
215
|
+
if (attributes) {
|
|
216
|
+
wwwAuthenticate += ',';
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
wwwAuthenticate += ` error="${Hoek.escapeHeaderAttribute(message)}"`;
|
|
220
|
+
err.output.payload.attributes.error = message;
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
err.isMissing = true;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
err.output.headers['WWW-Authenticate'] = wwwAuthenticate;
|
|
227
|
+
return err;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
exports.paymentRequired = function (message, data) {
|
|
232
|
+
|
|
233
|
+
return new exports.Boom(message, { statusCode: 402, data, ctor: exports.paymentRequired });
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
exports.forbidden = function (message, data) {
|
|
238
|
+
|
|
239
|
+
return new exports.Boom(message, { statusCode: 403, data, ctor: exports.forbidden });
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
exports.notFound = function (message, data) {
|
|
244
|
+
|
|
245
|
+
return new exports.Boom(message, { statusCode: 404, data, ctor: exports.notFound });
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
exports.methodNotAllowed = function (message, data, allow) {
|
|
250
|
+
|
|
251
|
+
const err = new exports.Boom(message, { statusCode: 405, data, ctor: exports.methodNotAllowed });
|
|
252
|
+
|
|
253
|
+
if (typeof allow === 'string') {
|
|
254
|
+
allow = [allow];
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (Array.isArray(allow)) {
|
|
258
|
+
err.output.headers.Allow = allow.join(', ');
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return err;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
exports.notAcceptable = function (message, data) {
|
|
266
|
+
|
|
267
|
+
return new exports.Boom(message, { statusCode: 406, data, ctor: exports.notAcceptable });
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
exports.proxyAuthRequired = function (message, data) {
|
|
272
|
+
|
|
273
|
+
return new exports.Boom(message, { statusCode: 407, data, ctor: exports.proxyAuthRequired });
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
exports.clientTimeout = function (message, data) {
|
|
278
|
+
|
|
279
|
+
return new exports.Boom(message, { statusCode: 408, data, ctor: exports.clientTimeout });
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
exports.conflict = function (message, data) {
|
|
284
|
+
|
|
285
|
+
return new exports.Boom(message, { statusCode: 409, data, ctor: exports.conflict });
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
exports.resourceGone = function (message, data) {
|
|
290
|
+
|
|
291
|
+
return new exports.Boom(message, { statusCode: 410, data, ctor: exports.resourceGone });
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
exports.lengthRequired = function (message, data) {
|
|
296
|
+
|
|
297
|
+
return new exports.Boom(message, { statusCode: 411, data, ctor: exports.lengthRequired });
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
exports.preconditionFailed = function (message, data) {
|
|
302
|
+
|
|
303
|
+
return new exports.Boom(message, { statusCode: 412, data, ctor: exports.preconditionFailed });
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
exports.entityTooLarge = function (message, data) {
|
|
308
|
+
|
|
309
|
+
return new exports.Boom(message, { statusCode: 413, data, ctor: exports.entityTooLarge });
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
exports.uriTooLong = function (message, data) {
|
|
314
|
+
|
|
315
|
+
return new exports.Boom(message, { statusCode: 414, data, ctor: exports.uriTooLong });
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
exports.unsupportedMediaType = function (message, data) {
|
|
320
|
+
|
|
321
|
+
return new exports.Boom(message, { statusCode: 415, data, ctor: exports.unsupportedMediaType });
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
exports.rangeNotSatisfiable = function (message, data) {
|
|
326
|
+
|
|
327
|
+
return new exports.Boom(message, { statusCode: 416, data, ctor: exports.rangeNotSatisfiable });
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
exports.expectationFailed = function (message, data) {
|
|
332
|
+
|
|
333
|
+
return new exports.Boom(message, { statusCode: 417, data, ctor: exports.expectationFailed });
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
exports.teapot = function (message, data) {
|
|
338
|
+
|
|
339
|
+
return new exports.Boom(message, { statusCode: 418, data, ctor: exports.teapot });
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
exports.badData = function (message, data) {
|
|
344
|
+
|
|
345
|
+
return new exports.Boom(message, { statusCode: 422, data, ctor: exports.badData });
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
exports.locked = function (message, data) {
|
|
350
|
+
|
|
351
|
+
return new exports.Boom(message, { statusCode: 423, data, ctor: exports.locked });
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
exports.failedDependency = function (message, data) {
|
|
356
|
+
|
|
357
|
+
return new exports.Boom(message, { statusCode: 424, data, ctor: exports.failedDependency });
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
exports.tooEarly = function (message, data) {
|
|
361
|
+
|
|
362
|
+
return new exports.Boom(message, { statusCode: 425, data, ctor: exports.tooEarly });
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
exports.preconditionRequired = function (message, data) {
|
|
367
|
+
|
|
368
|
+
return new exports.Boom(message, { statusCode: 428, data, ctor: exports.preconditionRequired });
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
exports.tooManyRequests = function (message, data) {
|
|
373
|
+
|
|
374
|
+
return new exports.Boom(message, { statusCode: 429, data, ctor: exports.tooManyRequests });
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
exports.illegal = function (message, data) {
|
|
379
|
+
|
|
380
|
+
return new exports.Boom(message, { statusCode: 451, data, ctor: exports.illegal });
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
// 5xx Server Errors
|
|
385
|
+
|
|
386
|
+
exports.internal = function (message, data, statusCode = 500) {
|
|
387
|
+
|
|
388
|
+
return internals.serverError(message, data, statusCode, exports.internal);
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
exports.notImplemented = function (message, data) {
|
|
393
|
+
|
|
394
|
+
return internals.serverError(message, data, 501, exports.notImplemented);
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
exports.badGateway = function (message, data) {
|
|
399
|
+
|
|
400
|
+
return internals.serverError(message, data, 502, exports.badGateway);
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
exports.serverUnavailable = function (message, data) {
|
|
405
|
+
|
|
406
|
+
return internals.serverError(message, data, 503, exports.serverUnavailable);
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
exports.gatewayTimeout = function (message, data) {
|
|
411
|
+
|
|
412
|
+
return internals.serverError(message, data, 504, exports.gatewayTimeout);
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
exports.badImplementation = function (message, data) {
|
|
417
|
+
|
|
418
|
+
const err = internals.serverError(message, data, 500, exports.badImplementation);
|
|
419
|
+
err.isDeveloperError = true;
|
|
420
|
+
return err;
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
internals.initialize = function (err, statusCode, message) {
|
|
425
|
+
|
|
426
|
+
const numberCode = parseInt(statusCode, 10);
|
|
427
|
+
Hoek.assert(!isNaN(numberCode) && numberCode >= 400, 'First argument must be a number (400+):', statusCode);
|
|
428
|
+
|
|
429
|
+
err.isBoom = true;
|
|
430
|
+
err.isServer = numberCode >= 500;
|
|
431
|
+
|
|
432
|
+
if (!err.hasOwnProperty('data')) {
|
|
433
|
+
err.data = null;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
err.output = {
|
|
437
|
+
statusCode: numberCode,
|
|
438
|
+
payload: {},
|
|
439
|
+
headers: {}
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
Object.defineProperty(err, 'reformat', { value: internals.reformat, configurable: true });
|
|
443
|
+
|
|
444
|
+
if (!message &&
|
|
445
|
+
!err.message) {
|
|
446
|
+
|
|
447
|
+
err.reformat();
|
|
448
|
+
message = err.output.payload.error;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
if (message) {
|
|
452
|
+
const props = Object.getOwnPropertyDescriptor(err, 'message') || Object.getOwnPropertyDescriptor(Object.getPrototypeOf(err), 'message');
|
|
453
|
+
Hoek.assert(!props || props.configurable && !props.get, 'The error is not compatible with boom');
|
|
454
|
+
|
|
455
|
+
err.message = message + (err.message ? ': ' + err.message : '');
|
|
456
|
+
err.output.payload.message = err.message;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
err.reformat();
|
|
460
|
+
return err;
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
internals.reformat = function (debug = false) {
|
|
465
|
+
|
|
466
|
+
this.output.payload.statusCode = this.output.statusCode;
|
|
467
|
+
this.output.payload.error = internals.codes.get(this.output.statusCode) || 'Unknown';
|
|
468
|
+
|
|
469
|
+
if (this.output.statusCode === 500 && debug !== true) {
|
|
470
|
+
this.output.payload.message = 'An internal server error occurred'; // Hide actual error from user
|
|
471
|
+
}
|
|
472
|
+
else if (this.message) {
|
|
473
|
+
this.output.payload.message = this.message;
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
internals.serverError = function (message, data, statusCode, ctor) {
|
|
479
|
+
|
|
480
|
+
if (data instanceof Error &&
|
|
481
|
+
!data.isBoom) {
|
|
482
|
+
|
|
483
|
+
return exports.boomify(data, { statusCode, message });
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
return new exports.Boom(message, { statusCode, data, ctor });
|
|
487
|
+
};
|