@ingeze/api-error - v1.0.8
    Preparing search index...

    Function createHandleError

    • Factory function to create strongly-typed custom error classes.

      Type Parameters

      • TType extends string = string

        A string literal type that defines specific error types.

      • TDetails extends Record<string, unknown> = Record<string, unknown>

        A shape of the additional metadata provided with the error.

      Parameters

      Returns new (
          message?: string,
          type?: TType,
          details?: TDetails,
      ) => ErrorHandler & {
          details?: TDetails;
          name: string;
          statusCode: number;
          type: TType;
      }

      A class constructor for the custom error.

      const PaymentFailedError = createHandleError({
      name: 'PaymentFailedError',
      statusCode: 402,
      defaultType: 'PAYMENT_FAILED',
      defaultMessage: 'Payment could not be processed'
      })

      throw new PaymentFailedError()
      throw new PaymentFailedError('Card declined', 'PAYMENT_DECLINED', { retry: false })