1.1.16 • Published 7 years ago
fel v1.1.16
fel
Exports the createError function that creates an error.
The error has a unique id and a reference to the cause, this is to facilitate with logging.
createError uses boom.wrap to decorate the error with boom properties.
createError takes the following optional params:
codeHTTP status code >= 400. Defaults to 500.messageError message. Defaults to the default message forcode.causeThe cause of the error.root_error_idId of the root cause. Defaults tocause.root_error_id || error_id.stack_fromFunction to start stack trace from. Defaults tocreateError.
The created error has the following properties added to it:
codeHTTP status codemessageError messagecauseThe causeerror_idA unique id stringroot_error_idA unique id stringoutputSee boomdetailsifcauseis a joi error then thedetailsarray is copied. It is also added tooutput.payload.
Example:
import { createError } from 'fel';
let error = createError();
// error.code == 500
// error.message == 'Internal Server Error'
// error.error_id == (unique id string)
// error.root_error_id == (unique id string)
createError({ code: 400 });
createError({ code: 400, message: 'cannot process the request' });
function readJsonFile(filename, callback) {
fs.readFile(filename, { encoding: 'utf8' }, (err, str) => {
if (err) {
return callback(createError({ cause: err, message: 'Unable to read the file' }));
}
let obj;
try {
obj = JSON.parse(str);
}
catch (json_err) {
return callback(createError({ cause: json_err, message: 'Unable to parse the file' }));
}
callback(null, obj);
});
}1.1.16
7 years ago
1.1.15
7 years ago
1.1.14
7 years ago
1.1.13
9 years ago
1.1.12
10 years ago
1.1.11
10 years ago
1.1.10
10 years ago
1.1.9
10 years ago
1.1.8
10 years ago
1.1.7
10 years ago
1.1.6
10 years ago
1.1.5
10 years ago
1.1.4
10 years ago
1.1.3
10 years ago
1.1.2
10 years ago
1.1.1
10 years ago
1.1.0
10 years ago
1.0.0
10 years ago