Core
Framework v2.x
2

wrap #

Available since 2.17.4

Returns helpers bound to a domain and a subdomain, so that the error name is the only thing left to give.

Arguments #

wrap (domain: string, subDomain: string): {
  get(error: string, ...placeholders: unknown[]): KuzzleError;
  getFrom(source: Error, error: string, ...placeholders: unknown[]): KuzzleError;
  reject(error: string, ...placeholders: unknown[]): Promise<never>;
}
ArgumentTypeDescription
domain
string
Domain name
subDomain
string
Subdomain name

Returns #

Returns an object with three methods:

MethodDescription
getSame as get, with the domain and subdomain already set
getFromSame as getFrom, with the domain and subdomain already set
rejectReturns a promise rejected with the error that get would return

An error name that is not registered in this domain and subdomain gives a core.fatal.unexpected_error error.

Usage #

app.errors.register('app', 'api', 'custom', {
  class: 'BadRequestError',
  description: 'This is a custom error from API subdomain',
  message: 'Custom %s error',
});

const apiError = app.errors.wrap('app', 'api');

throw apiError.get('custom', 'Tbilisi');