This package has been deprecated

Author message:

Deprecated

fel
TypeScript icon, indicating that this package has built-in type declarations

1.1.16 • Public • Published

fel

Greenkeeper badge

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:

  • code HTTP status code >= 400. Defaults to 500.
  • message Error message. Defaults to the default message for code.
  • cause The cause of the error.
  • root_error_id Id of the root cause. Defaults to cause.root_error_id || error_id.
  • stack_from Function to start stack trace from. Defaults to createError.

The created error has the following properties added to it:

  • code HTTP status code
  • message Error message
  • cause The cause
  • error_id A unique id string
  • root_error_id A unique id string
  • output See boom
  • details if cause is a joi error then the details array is copied. It is also added to output.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);
  });
}

Readme

Keywords

none

Package Sidebar

Install

npm i fel

Weekly Downloads

24

Version

1.1.16

License

MIT

Unpacked Size

203 kB

Total Files

13

Last publish

Collaborators

  • springworksdev
  • springworksprime