Skip to content

Latest commit

 

History

History
50 lines (40 loc) · 1.08 KB

no-unsafe-catch.md

File metadata and controls

50 lines (40 loc) · 1.08 KB

Avoid completing effects and epics (no-unsafe-catch)

This rule effects failures if catchError is used in an effect or epic in a manner that will complete the outermost observable.

Rule details

Examples of incorrect code for this rule:

actions.pipe(
  ofType("SOMETHING"),
  switchMap((action) => something(action)),
  catchError(handleError)
);

Examples of correct code for this rule:

actions.pipe(
  ofType("SOMETHING"),
  switchMap((action) => something(action).pipe(
    catchError(handleError)
  ))
);
actions.pipe(
  ofType("SOMETHING"),
  switchMap((action) => something(action)),
  catchError((error, caught) => {
    handleError(error);
    return caught;
  })
);

Options

This rule accepts a single option which is an object with an observable property that is a regular expression used to match an effect or epic's actions observable. The default observable regular expression should match most effect and epic action sources.

{
  "rxjs/no-unsafe-catch": [
    "error",
    { "observable": "[Aa]ction(s|s\\$|\\$)$" }
  ]
}