captbaritone / raven-for-redux

A Raven middleware for Redux
295 stars 25 forks source link

Support auto reporting of `error` FSA #28

Closed pke closed 7 years ago

pke commented 7 years ago

How about the middleware to catch FSA with error === true automatically. Whenever it sees a FSA with the error key set to true it could report the error.

if (action.error === true) {
  Raven.captureException(action.payload, {
    extra: action.meta
  });
}
captbaritone commented 7 years ago

Interesting! You could shoe-horn this functionality into raven-for-redux by putting your logic in breadcrumbDataFromAction, since that function gets called for every action. However, that's pretty gross.

const breadcrumbDataFromAction = (action) => {
  if (action.error === true) {
    Raven.captureException(action.payload, {
      extra: action.meta
    });
  }
};

const store = createStore(
    reducer,
    applyMiddleware(
        createRavenMiddleware(Raven, {
            breadcrumbDataFromAction
        })
    )
);

Or, you could just write it as its own middleware and it would be nearly as simple:

const fsaMiddleware = (store) => (next) => (action) => {
  if (action.error === true) {
    Raven.captureException(action.payload, {
      extra: action.meta
    });
  }
  return next(action);
};

const store = createStore(
    reducer,
    applyMiddleware(
        createRavenMiddleware(Raven),
        fsaMiddleware
    )
);

I don't think this makes sense to be in raven-for-redux as a core feature, since FSA, is just a subset of Redux usage. That being said, it might be nice to offer this via something like import createFsaRavenMiddleware from 'raven-for-redux/fsa';.

Can you think of other common patterns/feature that FSA/Raven users might want?

pke commented 7 years ago

Yeah I thought about just writing my own little middleware for that. I have no other common patterns in mind at the moment.

captbaritone commented 7 years ago

I haven't used FSA before. Is it common to do error handling inside the reducer? If so, reporting all action errors may not really be the right thing anyway.