npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@rnw-community/rxjs-errors

v1.8.2

Published

RxJS errors utils

Readme

RxJS error utils

Utils that help work with errors in rxjs observable's.

npm version npm downloads

Classes

  • RxJSFilterError - custom error used by error operators.

Available operators

  • filterWithException - works like filter from rxjs, but throw an error instead of ignoring the value.

  • rethrowException - will catch any error in the observable, create a new RxJSFilterError (or any custom) with custom message and log it with a custom logger function that you can optionally pass in. If it catches RxJSFilterError (or any custom), it will just rethrow that exception as is.

Usage examples

filterWithException

If the condition does not pass, will throw RxJSFilterError exception with passed in message.

import { of } from 'rxjs';
import { filterWithException } from '@rnw-community/rxjs-errors';

of('C')
    .pipe(
        filterWithException(
            letter => letter === 'A',
            letter => `Wanted A, but got ${letter}`
        )
    )
    .subscribe(value => console.log(value));

Passing custom error class:

import { filterWithException } from '@rnw-community/rxjs-errors';
import { BadRequestException } from '@nestjs/common';
import { of } from 'rxjs';

of('F')
    .pipe(
        filterWithException(
            letter => letter === 'A',
            letter => `Wanted A, but got ${letter}`,
            BadRequestException
        )
    )
    .subscribe(value => console.log(value));

Passing a type guard:

import { filterWithException } from '@rnw-community/rxjs-errors';
import { of } from 'rxjs';

const value: unknown = '';

const isString = (val: unknown): val is string => typeof val === 'string';

of(value) // `unknown` here
    .pipe(filterWithException(isString, value => `Wanted string, but got ${typeof value}`))
    .subscribe((value) /* `string` here */ => {
        console.log(value);
    });

You could also just pass in a message instead of a function:

import { of } from 'rxjs';
import { filterWithException } from '@rnw-community/rxjs-errors';

of('C')
    .pipe(filterWithException(letter => letter === 'A', 'Invalid letter recevied'))
    .subscribe(value => console.log(value));

rethrowException

In this example if the passed in letter is not A, then the RxJSFilterError will be thrown with "Invalid character" text. rethrowException will log it and throw it again as is.

If the this.repository.doSomething(letter) call will throw an error (not an instance of RxJSFilterError) it will log the thrown error, and then create a new one of type RxJSFilterError with "Could not check letter" text.

import { filterWithException, rethrowException } from '@rnw-community/rxjs-errors/src';
import { of } from 'rxjs';

class LetterService {
    constructor(private readonly repository: ILetterRepository) {}

    checkLetter$(letter: string): Observable<string> {
        return of(letter).pipe(
            filterWithException(letter !== 'A', 'Invalid character'),
            concatMap(letter => this.repository.doSomething(letter)),
            rethrowException('Could not check letter', console.error)
        );
    }
}

In this example any error except for LetterError will be caught, logged and a LetterError will be thrown with a "Could not check letter" message.

import { filterWithException, rethrowException } from '@rnw-community/rxjs-errors/src';
import { of } from 'rxjs';

class LetterError extends Error {}

class LetterService {
    constructor(private readonly repository: ILetterRepository) {}

    checkLetter$(letter: string): Observable<string> {
        return of(letter).pipe(
            filterWithException(letter !== 'A', 'Invalid character'),
            concatMap(letter => this.repository.doSomething(letter)),
            rethrowException('Could not check letter', console.error, LetterError)
        );
    }
}

You could also pass in a function, that will accept the caught error, to create an error message:

import { filterWithException, rethrowException } from '@rnw-community/rxjs-errors';
import { getErrorMessage } from '@rnw-community/shared';
import { of } from 'rxjs';

class LetterService {
    constructor(private readonly repository: ILetterRepository) {}

    checkLetter$(letter: string): Observable<string> {
        return of(letter).pipe(
            filterWithException(letter !== 'A', 'Invalid character'),
            concatMap(letter => this.repository.doSomething(letter)),
            rethrowException((err: unknown) => getErrorMessage(err), console.error)
        );
    }
}

If you don't want to log anything, you can just not pass in a log function:

import { filterWithException, rethrowException } from '@rnw-community/rxjs-errors';
import { getErrorMessage } from '@rnw-community/shared';
import { of } from 'rxjs';

class LetterService {
    constructor(private readonly repository: ILetterRepository) {}

    checkLetter$(letter: string): Observable<string> {
        return of(letter).pipe(
            filterWithException(letter !== 'A', 'Invalid character'),
            concatMap(letter => this.repository.doSomething(letter)),
            rethrowException('Could not check letter')
        );
    }
}

License

This library is licensed under The MIT License.