{"id":18412707,"url":"https://github.com/platzidev/redux-catch","last_synced_at":"2025-04-07T15:09:04.280Z","repository":{"id":50351275,"uuid":"56124194","full_name":"PlatziDev/redux-catch","owner":"PlatziDev","description":"Error catcher middleware for Redux reducers and sync middlewares","archived":false,"fork":false,"pushed_at":"2016-12-10T05:17:40.000Z","size":14,"stargazers_count":151,"open_issues_count":1,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-05-18T18:02:19.247Z","etag":null,"topics":["error-catcher-middleware","error-handler","middleware","redux-catch","redux-middleware","sentry"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/redux-catch","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PlatziDev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-13T05:41:27.000Z","updated_at":"2023-05-27T18:15:49.000Z","dependencies_parsed_at":"2022-09-17T01:23:44.022Z","dependency_job_id":null,"html_url":"https://github.com/PlatziDev/redux-catch","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PlatziDev%2Fredux-catch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PlatziDev%2Fredux-catch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PlatziDev%2Fredux-catch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PlatziDev%2Fredux-catch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PlatziDev","download_url":"https://codeload.github.com/PlatziDev/redux-catch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247675597,"owners_count":20977376,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["error-catcher-middleware","error-handler","middleware","redux-catch","redux-middleware","sentry"],"created_at":"2024-11-06T03:43:11.909Z","updated_at":"2025-04-07T15:09:04.263Z","avatar_url":"https://github.com/PlatziDev.png","language":"JavaScript","readme":"# redux-catch\nError catcher middleware for Redux reducers and sync middlewares.\n\n[![Build Status](https://travis-ci.org/PlatziDev/redux-catch.svg?branch=master)](https://travis-ci.org/PlatziDev/redux-catch)\n[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)\n\n## API\n### Apply middleware\n```javascript\nimport { createStore, applyMiddleware } from 'redux';\n\nimport reduxCatch from 'redux-catch';\n\nimport reducer from './reducer';\n\nfunction errorHandler(error, getState, lastAction, dispatch) {\n  console.error(error);\n  console.debug('current state', getState());\n  console.debug('last action was', lastAction);\n  // optionally dispatch an action due to the error using the dispatch parameter\n}\n\nconst store = createStore(reducer, applyMiddleware(\n  reduxCatch(errorHandler)\n));\n```\n\n- `reduxCatch` receive a function to use when an error happen.\n- The error handler function could be just a `console.error` like the example above or a function to log the error in some kind of error tracking platform.\n- You should use this middleware as the first middleware in the chain, so its allowed to catch all the possible errors in the application.\n\n### Using it with [Sentry](https://www.getsentry.com/)\nTo use it with Sentry just download the Sentry script from npm:\n\n```bash\nnpm i -S raven-js raven\n```\n\n- [raven-js](https://www.npmjs.com/package/raven-js): This is the client for browser usage.\n- [raven-node](https://github.com/getsentry/raven-node): This is the client for server usage.\n\nNow load and configure your client:\n\n```javascript\nimport Raven from 'raven-js';\n\nconst sentryKey = '\u003ckey\u003e';\n\nRaven\n  .config(`https://${sentryKey}@app.getsentry.com/\u003cproject\u003e`)\n  .install();\n```\n\nAnd then use `Raven.captureException` as the error handler like this:\n\n```javascript\nconst store = createStore(reducer, applyMiddleware(\n  reduxCatch(error =\u003e Raven.captureException(error));\n));\n```\n\nNow `redux-catch` will start to send the errors of your reducers and middlewares to Sentry.\n\n#### Add state as extra data\nYou can also add the state data as extra data for your errors so you can know the state at the moment of the error.\n\n```javascript\nfunction errorHandler(error, getState, action) {\n  Raven.context({\n    state: getState(),\n    action,\n  });\n  Raven.captureException(error);\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplatzidev%2Fredux-catch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplatzidev%2Fredux-catch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplatzidev%2Fredux-catch/lists"}