Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

gunar/rx-graceful

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rx-graceful rxjs logo

CircleCI

Makes RxJS Subjects graceful. Why? Because...

  • Exceptions usually terminate Subjects and often swallow errors.
  • It's naive to be confident our code does not contain an exception.

Installation

npm install rx-graceful

Example

'use strict'

const Rx = require('rxjs')

require('rx-graceful')(Rx)

const $ = new Rx.Subject()

$
  // (1) catches exceptions inside map
  .map(() => { throw Error() })
  // (2) catches rejections inside flatMap
  .flatMap(x => Promise.reject())
  // (3) catches exceptions inside async functions (as these are rejections as well)
  .flatMap(async x => { throw Error() })
  .subscribe(x => {
    // (4) catches exceptions inside the subscription handler
    throw Error()
  }, e => {
    // Handles errors (1), (2), (3), (4)
  })

$.next('some value')

Future improvements

  • Use lettable operators instead of mutating Subject.prototype, as soon as they're out of beta

About

Make RxJS handle errors gracefully

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published