Setu-TS
    Preparing search index...

    Function withHttpStatusHint

    • Brands an error with the status it should be answered with.

      The error is branded in place and returned, so identity is preserved and a throw withHttpStatusHint(new Xyz(…), hint) reads as one statement. The property is symbol-keyed and non-enumerable, so it is invisible to Object.keys, JSON.stringify and spread, and the error behaves exactly as it did — instanceof, name, message and cause are all untouched.

      Type Parameters

      • T extends Error

        The error type, preserved in the return

      Parameters

      • error: T

        The error to brand

      • hint: HttpStatusHint

        How it should be answered

      Returns T

      The same error reference, branded

      If error is frozen, sealed, or otherwise not extensible — the brand is defined as a property on the error itself

      export class UnsupportedThingError extends Error {
      constructor(thing: string, message: string) {
      super(message);
      withHttpStatusHint(this, {
      status: 501,
      title: 'Not Implemented',
      detail: `'${thing}' is not supported.`,
      });
      }
      }

      0.4.0