Err

Bajo error class, a thin wrapper of node's Error object.

Every Bajo plugin has a built-in method called error which basically the shortcut to create a new Err instance. It helps you create this instance anywhere in your code quickly without the hassle of importing & instantiating:

... anywhere inside your code
if (notfound) throw this.error('Sorry, item is nowhere to be found!')

Constructor

new Err(plugin, msg, …argsopt)

Constructor.

Parameters:
NameTypeAttributesDescription
pluginPlugin

Plugin instance

msgstring

Error message

argsany<optional>
<repeatable>

Variables to interpolate with error message. Payload object can be pushed at the very last argument

Members

message :string

Translated message.

Type:
  • string

orgMessage :string

Original message before translation.

Type:
  • string

payload :Object

Error payload extracted from the last arguments.

Type:
  • Object

Methods

fatal()

Print instance on console and terminate process.

formatErrorDetails(value) → {Object}

Pretty format error details.

Formatted error will be applied directly to the value parameter, and a detailsMessage will be returned for display purpose.

Parameters:
NameTypeDescription
valueObject

Value to format

Returns:
Type: 
Object

write() → {Err}

Write message to the console.

Returns:
  • Error object, useful for chaining
Type: 
Err