Expressify exports some error types it uses internally.

const {
    AmbassifyError,
    ValidationError,
    InvalidOrganizationError,
    InsufficientPermissionsError,
} = require('@ambassify/expressify/error');

AmbassifyError

Base error class. This is an export of @ambassify/error. Extend this to get the most out of our custom serializers. If you install @ambassify/error yourself, you might end up with a different version which will break expressify’s serializers.

ValidationError

A validation error, contains at least the following properties:

  • message: description of the error
  • path: ordered array where each element is the accessor to the value where the error happened

The validation middleware for example will add extra properties returned by Joi.

InvalidOrganizationError

An authorization error indicating an invalid organization, contains at least the following properties:

  • message: description of the error
  • expected: the expected organization (can be a Boolean too)
  • actual: the organization found in the request

The authoirzation middleware uses this when the error handler is not customized.

InsufficientPermissionsError

An authorization error, contains at least the following properties:

  • message: description of the error
  • got: an array containing the owner scope of the request
  • need: an object { anyOf, allOf, noneOf } containing the parsed and interpolated required scope for the request

The authoirzation middleware uses this when the error handler is not customized.

Logging errors

An error logging utility method is also provided that helps you log errors using an Expressify-compatible logger. It takes care of detecting the right log level, logref, …

const { logError } = require('@ambassify/expressify/error');
const error = new Error('it broke');

logError(error, { logger: myLogger, req, res });