Skip to content

killtheliterate/redux-saga-try-catch

Repository files navigation

Build Status Standard - JavaScript Style Guide npm version

redux-saga-try-catch

includes TypeScript definitions

A saga utility to reduce flow control boilerplate. See the tests.

Install

$ npm install redux-saga-try-catch

Use

FSA

import Catch from 'redux-saga-try-catch'

const io = {
  log: console.log
}

function* aSaga() {
  throw new Error('oh no!')
}

const aSafeSaga = Catch.standardAction(aSaga, io)

aSafeSaga({ type: 'AN_ACTION' }) // logs the error

FSA with meta

import Catch from 'redux-saga-try-catch'

const io = {
  log: console.log
}

function* aSaga() {
  throw new Error('oh no!')
}

const aSafeSaga = Catch.deferredAction(aSaga, io)

const action = { 
  type: 'AN_ACTION',
  meta: {
    deferred: { 
      success: console.log, // a success callback - could be `resolve`
      failure: console.err  // a failure callback - could be `reject`
    }
  }
}

aSafeSaga() // logs the error