Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@mixer/epic-supervisor
Advanced tools
redux-observable is an RxJS-based side effects module for Redux. Unfortunately, it lacks a built-in way to handle uncaught errors, which by default are unlogged and break all epics in the application. The maintainers have indicated that there's no immediate plans to implement a 'first-party' solution for error handling. So, this is ours! This module implements an Erlang/OTP-style supervisor pattern for epics. Out of the box it provides a combineEpics
-compatible function which instruments epics with error logging, and provides an additional superviseEpics
method which provides additional supervision options for epics.
// 1. import from this module, instead of redux-observable:
import { combineEpics } from '@mixer/epic-supervisor';
// 2. Define your epics...
const fooEpic = /* ... */;
const barEpic = /* ... */;
// 3. combineEpics() like you normall would:
export const myEpics = combineEpics(fooEpic, barEpic);
combineEpics(...epics)
By default, this method functions identically to combineEpics
from redux-observable
.
superviseEpics(options, ...epics)
This works like combineEpics
, except with an options argument in front. The options object can take several parameters, all optional:
noRestarts
, oneForOne
, oneForAll
, or restForOne
. See the erlang supervisor page for nice diagrams of these. Defaults to noRestarts
, indicating restarts will not occur.catchError()
-- it will be invoked with the error context object (see beow) that occurs, followed by the actions, state, and services just like a normal epic. If restart is enabled we'll wait for the returned observable to emit before restarting epics. If an error is thrown or rethrown from this method, it will bubble up to any parent supervisor.onError
.Example:
import { superviseEpics, oneForOne } from '@mixer/epic-supervisor';
import { timer } from 'rxjs';
const fooEpic = /* ... */;
const barEpic = /* ... */;
const options = {
restart: oneForOne,
onError: ({ epicName, error }, actions, state, services) => {
// Send another action when the error occurs:
actions.dispatch(doLogErrorAction({ message: `An error occurred in epic ${epicName}`, error }));
// Wait a second before restarting epics:
return timer(1000);
},
onRestart (_, actions) => {
actions.dispatch(restartMyService());
},
};
superviseEpics(options, fooEpic, barEpic);
configure(options)
Configures the global/default options for epic-supervisor. The options object can take several parameters, all optional:
onError
method.import { configure } from '@mixer/epic-supervisor';
configure({
onAnyError: context => myLogger.warn(context),
onUnhandledError: context => myLogger.error(context),
});
The error context (IErrorContext
for TypeScript consumers) captures thrown errors along with some metadata--as rxjs stacktraces are often inscrutable. It has the following properties:
null
for epics that lack a function name.innerError
, the original error that occurred. Returns the current error context if there is no innerError.FAQs
Supervisor tree for react-redux error handling
We found that @mixer/epic-supervisor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.