Skip to content

killtheliterate/redux-saga-try-catch

Folders and files

NameName
Last commit message
Last commit date
Dec 14, 2023
Nov 4, 2024
Jun 4, 2018
Jun 5, 2018
May 21, 2024
Jun 5, 2018
Jun 17, 2019
Nov 4, 2024
Jan 2, 2025
Jan 1, 2025
Nov 4, 2024
Nov 4, 2024
Mar 27, 2023
Mar 27, 2023
Mar 27, 2023

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