Abstract Class: Exception
The base class of the framework's exceptions, and of the applications' own: extend it, set its errno and, for the errors sent to clients, its statusCode. The entrypoints send errno, errMsg and statusCode to the clients, and the HTTP adapters reply with statusCode.
The message is built from the constructor arguments:
new XxxException('Order {id} not found', {id: 1}): a template, its{name}placeholders filled from an object, or its{0},{1}placeholders from the parameters given one by one (new XxxException('{0} of {1}', a, b)) or from an array; theutil.format()placeholders (%s,%d,%j…) are filled from the parameters too. A missing value leaves its placeholder in the message; building the message never throws.new XxxException('Order not found'): the message as given.new XxxException(error): the message of another error.new XxxException(): a message made from the words of the class name, the acronyms kept (Order not found exceptionforOrderNotFoundException,HTTP request exceptionforHTTPRequestException).
The template parameters are kept for the translation of the message, see exceptionParams.
Example
import {Exception} from 'lakutata'
export class OrderNotFoundException extends Exception {
public errno: string = 'E_ORDER_NOT_FOUND'
public readonly statusCode: number = 404
}
export function findOrder(id: number): never {
throw new OrderNotFoundException('Order {id} not found', {id: id})
}Extends
Error
Extended by
SchemaExceptionContainerdConnectionExceptionContainerdContainerNameConflictExceptionContainerdContainerNotFoundExceptionContainerdContainerStateExceptionContainerdImageBuildExceptionContainerdImageExportExceptionContainerdImageImportExceptionContainerdImageNotFoundExceptionContainerdImagePullExceptionContainerdImagePushExceptionContainerdNetworkConflictExceptionContainerdNetworkNotFoundExceptionContainerdPathNotFoundExceptionContainerdPlatformExceptionContainerdVolumeInUseExceptionContainerdVolumeNotFoundExceptionDockerConnectionExceptionDockerContainerNotFoundExceptionDockerImageBuildExceptionDockerImageImportExceptionDockerImageNotFoundExceptionDockerImagePullExceptionDockerImagePushExceptionDockerImageRepoTagNotFoundExceptionDockerNetworkNotFoundExceptionDockerRequestExceptionCacheDriverNotFoundExceptionMutexTimeoutExceptionMutexLostExceptionMutexDriverExceptionMutexDriverNotFoundExceptionQueueCapabilityExceptionQueueInvalidMessageExceptionQueueRequestTimeoutExceptionQueueResultNotFoundExceptionQueueResultExpiredExceptionQueueAmbiguousGroupExceptionQueueProcessingTimeoutExceptionQueueDiscardExceptionQueueJobFailedExceptionQueueDriverNotFoundExceptionQueueDriverVersionExceptionI18nCatalogExceptionI18nMessageSyntaxExceptionI18nMissingKeyExceptionI18nMissingParameterExceptionI18nTranslatorExceptionAccessDeniedExceptionDuplicateActionNameExceptionControllerActionNotFoundExceptionInvalidMiddlewareExceptionMiddlewareNextCalledExceptionInvalidPrefixExceptionInvalidChannelExceptionInvalidEntrypointAdapterExceptionRouteNotFoundExceptionEntrypointStoppedExceptionServiceInvokeExceptionPasswordTooLongExceptionInvalidSignatureExceptionDecryptionFailedExceptionAliasExistsExceptionAliasNotFoundExceptionInvalidAliasNameExceptionDependencyInjectionExceptionLifetimeLockedExceptionOverridableObjectTargetConfigNotFoundExceptionInvalidObjectOptionsExceptionInvalidMethodAcceptExceptionInvalidMethodReturnExceptionInvalidValueExceptionDestroyRuntimeContainerExceptionInvalidActionPatternDepthExceptionInvalidAssistantFunctionTypeExceptionInvalidObjectTypeExceptionMethodNotFoundExceptionObjectDestroyedException
Constructors
Constructor
new Exception(
template, ...params):Exception
Parameters
template
string
params
...any[]
Returns
Exception
Overrides
Error.constructor
Constructor
new Exception(
message):Exception
Parameters
message
string
Returns
Exception
Overrides
Error.constructor
Constructor
new Exception(
error):Exception
Parameters
error
Error
Returns
Exception
Overrides
Error.constructor
Constructor
new Exception():
Exception
Returns
Exception
Overrides
Error.constructor
Properties
appId
readonlyappId:string
The ID of the application the exception was created in, "Unknown" before the application's options are loaded.
appName
readonlyappName:string
The name of the application the exception was created in, "Unknown" before the application's options are loaded.
cause?
optionalcause?:unknown
Inherited from
Error.cause
err
readonlyerr:string
The name of the exception's class ('OrderNotFoundException'), a copy of name kept as an own property.
errMsg
readonlyerrMsg:string
The formatted message, a copy of message kept as an own property (sent with the error by the entrypoints).
errno
abstracterrno:string|number
The error number or code identifying the error to the clients and the logs ('E_ORDER_NOT_FOUND'); each subclass sets it.
message
message:
string
Inherited from
Error.message
stack?
optionalstack?:string
Inherited from
Error.stack
stackTraceLimit
staticstackTraceLimit:number
The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).
The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.
If set to a non-number value, or set to a negative number, stack traces will not capture any frames.
Inherited from
Error.stackTraceLimit
statusCode
readonlystatusCode:number
The HTTP status the HTTP entrypoints reply with when the exception fails a request; a subclass overrides it (404 for a missing resource…).
Default
500Accessors
name
Get Signature
get name():
string
The name of the exception: the name of its class.
Returns
string
The class name.
Overrides
Error.name
Methods
captureStackTrace()
staticcaptureStackTrace(targetObject,constructorOpt?):void
Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.
The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();Parameters
targetObject
object
constructorOpt?
Function
Returns
void
Inherited from
Error.captureStackTrace
prepareStackTrace()
staticprepareStackTrace(err,stackTraces):any
Parameters
err
Error
stackTraces
CallSite[]
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
Error.prepareStackTrace