error-mapper-decorator
    Preparing search index...

    Function MapErrors

    • Method decorator that translates errors thrown by a method according to an ordered list of rules. Unmatched errors are rethrown as-is, so domain exceptions and genuine bugs pass through untouched. Order rules by specificity: a subclass error rule must precede its superclass rule. Have each rule's to pass the original error as cause to preserve its stack chain.

      Apply it to a single method, or to a whole class to wrap every instance method. The class form takes an optional leading options object to narrow the set with include/exclude. By default the rules run as a pipeline — each matching rule's output feeds the next (A → B → C); pass pipeline: false to stop at the first match.

      @MapErrors(rule1, rule2)                         // every instance method
      @MapErrors({ exclude: ["healthCheck"] }, rule1) // all but healthCheck
      @MapErrors({ pipeline: false }, ruleA, ruleB) // stop at first match
      class Service {}

      When a method is reached by more than one annotation — its own method-level @MapErrors, its class's, and any annotated ancestor's — the rule lists are merged most-specific-first (method > child-class > parent-class); the most-specific annotation also decides the pipeline mode. The effective list is resolved from the runtime receiver, so a subclass's class-level rules apply to methods it inherits.

      The wrapper preserves each method's return type, name, and arity (length) — synchronous methods stay synchronous, async methods stay async; rejections are mapped on the promise.

      Works under both legacy experimentalDecorators and TC39 Stage-3 decorators; the returned function detects the standard and the target at runtime.

      Type Parameters

      Parameters

      • ...rules: ErrorRules<C>

      Returns MapErrorsDecorator

    • Method decorator that translates errors thrown by a method according to an ordered list of rules. Unmatched errors are rethrown as-is, so domain exceptions and genuine bugs pass through untouched. Order rules by specificity: a subclass error rule must precede its superclass rule. Have each rule's to pass the original error as cause to preserve its stack chain.

      Apply it to a single method, or to a whole class to wrap every instance method. The class form takes an optional leading options object to narrow the set with include/exclude. By default the rules run as a pipeline — each matching rule's output feeds the next (A → B → C); pass pipeline: false to stop at the first match.

      @MapErrors(rule1, rule2)                         // every instance method
      @MapErrors({ exclude: ["healthCheck"] }, rule1) // all but healthCheck
      @MapErrors({ pipeline: false }, ruleA, ruleB) // stop at first match
      class Service {}

      When a method is reached by more than one annotation — its own method-level @MapErrors, its class's, and any annotated ancestor's — the rule lists are merged most-specific-first (method > child-class > parent-class); the most-specific annotation also decides the pipeline mode. The effective list is resolved from the runtime receiver, so a subclass's class-level rules apply to methods it inherits.

      The wrapper preserves each method's return type, name, and arity (length) — synchronous methods stay synchronous, async methods stay async; rejections are mapped on the promise.

      Works under both legacy experimentalDecorators and TC39 Stage-3 decorators; the returned function detects the standard and the target at runtime.

      Type Parameters

      Parameters

      • options: PipelineOptions
      • ...rules: ErrorRules<C>

      Returns MapErrorsDecorator

    • Method decorator that translates errors thrown by a method according to an ordered list of rules. Unmatched errors are rethrown as-is, so domain exceptions and genuine bugs pass through untouched. Order rules by specificity: a subclass error rule must precede its superclass rule. Have each rule's to pass the original error as cause to preserve its stack chain.

      Apply it to a single method, or to a whole class to wrap every instance method. The class form takes an optional leading options object to narrow the set with include/exclude. By default the rules run as a pipeline — each matching rule's output feeds the next (A → B → C); pass pipeline: false to stop at the first match.

      @MapErrors(rule1, rule2)                         // every instance method
      @MapErrors({ exclude: ["healthCheck"] }, rule1) // all but healthCheck
      @MapErrors({ pipeline: false }, ruleA, ruleB) // stop at first match
      class Service {}

      When a method is reached by more than one annotation — its own method-level @MapErrors, its class's, and any annotated ancestor's — the rule lists are merged most-specific-first (method > child-class > parent-class); the most-specific annotation also decides the pipeline mode. The effective list is resolved from the runtime receiver, so a subclass's class-level rules apply to methods it inherits.

      The wrapper preserves each method's return type, name, and arity (length) — synchronous methods stay synchronous, async methods stay async; rejections are mapped on the promise.

      Works under both legacy experimentalDecorators and TC39 Stage-3 decorators; the returned function detects the standard and the target at runtime.

      Type Parameters

      Parameters

      Returns MapErrorsClassDecorator