1.0.0 • Published 7 years ago

flux-standard-error v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

flux-standard-error

A simple function to consistently generate standard Flux Action Errors. It follows these simple rules:

  • An error property must exist, and will be set to true
  • The payload must be the Error.

Usage

Sample Action

import createError from 'flux-standard-error';

const myFancyAction = () => (dispatch) => {
   try { 
       // some error happens
   } catch(e) {
       dispatch(createError(e, MY_UNEXPECTED_ERROR, MY_FANCY_ACTION))
   }
}

It takes the following arguments, taken from the jsdoc

/*
 * @param {Error} error - The actual Error object
 * @param {string} type - The type to dispatch
 * @param {string} cause - The cause of the error
 * @param {object} [meta] - Additional information to be inserted into the meta property
 * @returns {{type: string, payload: Error, error: boolean, meta: {cause: string}}}
 */

The meta object is useful to stuffing in any additional data that might be needed to handle the error.