Stratal API Reference
    Preparing search index...

    Class ApplicationErrorAbstract

    ApplicationError

    Abstract base class for all application errors. This class should never be used directly - always extend it to create specific error types.

    Features:

    • Type-safe error codes from ERROR_CODES registry
    • Type-safe message keys from i18n module
    • Localized message keys (translated by GlobalErrorHandler)
    • Structured metadata for logging and interpolation
    • Proper Error prototype chain
    • Automatic timestamp generation
    • Serialization for RPC transmission

    Message Localization:

    • Each error class defines a message key (e.g., 'errors.userNotFound')
    • Metadata provides interpolation parameters (e.g., { userId: '123' })
    • GlobalErrorHandler translates the message key using I18nService before sending response
    • This ensures errors are localized based on the user's locale (from X-Locale header)

    Hierarchy (View Summary)

    Index

    Constructors

    • Parameters

      • messageKey: MessageKeys

        Type-safe i18n message key (e.g., 'errors.userNotFound')

      • code:
            | 1000
            | 1001
            | 1002
            | 1003
            | 1004
            | 2000
            | 2001
            | 2002
            | 2003
            | 2004
            | 2005
            | 2006
            | 2007
            | 2008
            | 3000
            | 3001
            | 3002
            | 3003
            | 3004
            | 3005
            | 3007
            | 3008
            | 3009
            | 3010
            | 3011
            | 3012
            | 3013
            | 3014
            | 3015
            | 3100
            | 3101
            | 3102
            | 4000
            | 4004
            | 4100
            | 4101
            | 9000
            | 9005
            | 9006
            | 9008
            | 9100
            | 9101
            | 9102
            | 9103
            | 9104
            | 9105
            | 9106
            | 9200
            | 9201
            | 9202
            | 9203
            | 9204
            | 9205
            | 9300
            | 9301

        Type-safe error code from ERROR_CODES registry

      • Optionalmetadata: Record<string, unknown>

        Optional data for logging and interpolation

      Returns ApplicationError

    Properties

    cause?: unknown
    code:
        | 1000
        | 1001
        | 1002
        | 1003
        | 1004
        | 2000
        | 2001
        | 2002
        | 2003
        | 2004
        | 2005
        | 2006
        | 2007
        | 2008
        | 3000
        | 3001
        | 3002
        | 3003
        | 3004
        | 3005
        | 3007
        | 3008
        | 3009
        | 3010
        | 3011
        | 3012
        | 3013
        | 3014
        | 3015
        | 3100
        | 3101
        | 3102
        | 4000
        | 4004
        | 4100
        | 4101
        | 9000
        | 9005
        | 9006
        | 9008
        | 9100
        | 9101
        | 9102
        | 9103
        | 9104
        | 9105
        | 9106
        | 9200
        | 9201
        | 9202
        | 9203
        | 9204
        | 9205
        | 9300
        | 9301

    Type-safe error code from ERROR_CODES registry See error-codes.ts for the complete registry

    message: string
    metadata?: Record<string, unknown>

    Additional structured data about the error Used for:

    1. Logging and debugging
    2. Message interpolation (e.g., { userId: '123', email: 'user@example.com' })
    name: string
    stack?: string
    timestamp: string

    ISO timestamp when the error was created

    stackTraceLimit: 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.

    Methods

    • 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
      • OptionalconstructorOpt: Function

      Returns void

    • Indicates whether the argument provided is a built-in Error instance or not.

      Parameters

      • error: unknown

      Returns error is Error