Function formatError

  • A simple method used throughout Libauth to format error messages. By formatting errors this way, downstream consumers can detect specific error types by matching the errorType. For example, the error:

    formatError(SomeTypeOfError.exceedsMaximum, `Provided value: ${value}`);

    Can be detected with String.includes(), even if the SomeTypeOfError.exceedsMaximum error message changes:

    // => true

    Using this method ensures consistency across the library.


    In Libauth, expected errors use the type string rather than Error (or other objects that inherit from Error) to simplify the resulting types and typechecking requirements. This ensures consistency of returned errors in all environments, avoids exposing internal details like stack traces and line numbers, and allows error messages to be recorded or used as text without an intermediate toString() method.


    • errorType: string

      the error enum member representing this error type

    • Optional errorDetails: string

      optional, additional details to include in the error message

    Returns string

Generated using TypeDoc