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>;
}| Argument | Type | Description |
|---|---|---|
domain | string | Domain name |
subDomain | string | Subdomain name |
Returns #
Returns an object with three methods:
| Method | Description |
|---|---|
get | Same as get, with the domain and subdomain already set |
getFrom | Same as getFrom, with the domain and subdomain already set |
reject | Returns 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');