throwError

throwError

throwError は、即座に error state になる Observable を返す operator です。

const { throwError } = require("rxjs");

const throwError$ = throwError(new Error("Custom Error"));

range$.subscribe({
  next: () => console.log("Never reach here"),
  error: (error) => console.error(error),
});
Error: Custom Error
    at Object.<anonymous> (/Users/myhome/learn-rxjs-for-angular/tmp.js:3:32)
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47