{"id":22231234,"url":"https://github.com/jneidel/err-hndlr","last_synced_at":"2025-03-25T09:12:17.896Z","repository":{"id":57226684,"uuid":"148974118","full_name":"jneidel/err-hndlr","owner":"jneidel","description":"Error handler for either throwing locally or sending a bug ticket to a rest api","archived":false,"fork":false,"pushed_at":"2019-01-24T21:07:00.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T15:59:56.580Z","etag":null,"topics":["error-handler","error-handling","error-log","errors","node-module"],"latest_commit_sha":null,"homepage":null,"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/jneidel.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":"2018-09-16T07:39:52.000Z","updated_at":"2019-01-24T21:07:02.000Z","dependencies_parsed_at":"2022-08-22T12:21:04.354Z","dependency_job_id":null,"html_url":"https://github.com/jneidel/err-hndlr","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jneidel%2Ferr-hndlr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jneidel%2Ferr-hndlr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jneidel%2Ferr-hndlr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jneidel%2Ferr-hndlr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jneidel","download_url":"https://codeload.github.com/jneidel/err-hndlr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245431733,"owners_count":20614184,"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-handler","error-handling","error-log","errors","node-module"],"created_at":"2024-12-03T01:20:10.607Z","updated_at":"2025-03-25T09:12:17.244Z","avatar_url":"https://github.com/jneidel.png","language":"JavaScript","readme":"# err-hndlr\n\n\u003e Error handler for either throwing locally or sending a bug ticket to a rest api\n\n[![Travis Build Status](https://img.shields.io/travis/jneidel/err-hndlr.svg?style=flat-square)](https://travis-ci.org/jneidel/err-hndlr)\n[![License MIT](https://img.shields.io/badge/license-MIT-green.svg?style=flat-square)](https://github.com/jneidel/err-hndlr/blob/master/license)\n[![Npm Downloads](https://img.shields.io/npm/dw/err-hndlr.svg?style=flat-square)](https://www.npmjs.com/package/err-hndlr)\n\n## Install\n\n[![Npm Version](https://img.shields.io/npm/v/err-hndlr.svg?style=flat-square)](https://www.npmjs.com/package/err-hndlr)\n\n```\n$ npm install err-hndlr\n```\n\n## Usage\n\n```js\nconst errHndlr = require( \"err-hndlr\" );\n\nerrHndlr.init(\n  process.argv[2] === \"--debug\",\n  \"https://api.jneidel.com/errors/submit\",\n  {\n    applicationId: \"1337\"\n  }\n)\n\nerrHndlr.throw(\n  \"smt went wrong\",\n  {\n    env: {...},\n  },\n  false\n)\n\n// If --debug flag was passed:\n//=\u003e Error: something went wrong\n\n// If --debug flag was not passed:\n// POST https://api.jneidel.com/error/submit\n//    {\n//      applicationId: \"1337\",\n//      error: {\n//        msg: \"smt went wrong\",\n//        stack: \"...\",\n//      },\n//      env: {...},\n//    }\n```\n\n\n## API\n\n### init( isThrow, apiAddress, data, options )\n\nGlobally initializes the error handler. This function has to be run before throwing any errors.\n\n```js\nerrHndlr.init(\n  false,\n  http://api.jneidel.com/errors/submit,\n  { id: \"1337\" },\n)\n```\n\n**isThrow:**\n\n\u003ctable\u003e\u003ctr\u003e\n  \u003ctd\u003eDefault: \u003ccode\u003etrue\u003c/code\u003e\u003c/td\u003e\n  \u003ctd\u003eType: \u003ccode\u003eboolean\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\u003c/table\u003e\n\nWhenever errors should be thrown locally (`true`) or be sent to the rest api (`false`).\n\n**apiAddress:**\n\n\u003ctable\u003e\u003ctr\u003e\n  \u003ctd\u003eType: \u003ccode\u003estring\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\u003c/table\u003e\n\nRest api endpoint where error requests should be sent if `isThrow=false`. The data will be sent in the body of the POST request.\n\n**data:**\n\n\u003ctable\u003e\u003ctr\u003e\n  \u003ctd\u003eDefault: \u003ccode\u003e{}\u003c/code\u003e\u003c/td\u003e\n  \u003ctd\u003eType: \u003ccode\u003eobject\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\u003c/table\u003e\n\nThe data that will be sent along on every request. You might want to include device specific data (os, etc.) and application data (name, version, etc.) here.\n\n**options:**\n\n\u003ctable\u003e\u003ctr\u003e\n  \u003ctd\u003eDefault: \u003ccode\u003e{}\u003c/code\u003e\u003c/td\u003e\n  \u003ctd\u003eType: \u003ccode\u003eobject\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\u003c/table\u003e\n\nCurrently supported options are:\n\n**app:**\n\nRequire your package.json through the app option to include the app's name and version in every request.\n\n```js\n// options:\n{\n  app: require( \"../package.json\" )\n}\n// POST request:\n{\n  ...\n  app: {\n    name: \"err-hndlr\",\n    version: \"0.0.1\",\n  }\n}\n```\n\n**os:**\n\nPass a truthy value to include the `os.type()` and `os.platform()` in every request.\n\n```js\n// options:\n{\n  os: true\n}\n// POST request:\n{\n  ...\n  os: {\n    type: \"Linux\",\n    platform: \"linux\",\n  }\n}\n```\n\n### throw( msg, data, isExit )\n\n```js\nerrHndlr.throw(\n  \"something went wrong\",\n  data: {\n    env: {...}\n  },\n  false,\n).catch( err =\u003e {...} ) // To handle connection errors (ECONNREFUSED)\n```\n\n**msg:**\n\n\u003ctable\u003e\u003ctr\u003e\n  \u003ctd\u003eType: \u003ccode\u003estring\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\u003c/table\u003e\n\nThe message used to call `new Error( msg )`.\n\n**data:**\n\n\u003ctable\u003e\u003ctr\u003e\n  \u003ctd\u003eDefault: \u003ccode\u003e{}\u003c/code\u003e\u003c/td\u003e\n  \u003ctd\u003eType: \u003ccode\u003eobject\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\u003c/table\u003e\n\nData to be include on this specific request. Might include environmental variables, state, etc.\n\n**isExit:**\n\n\u003ctable\u003e\u003ctr\u003e\n  \u003ctd\u003eDefault: \u003ccode\u003efalse\u003ccode\u003e\u003c/td\u003e\n  \u003ctd\u003eType: \u003ccode\u003eboolean\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\u003c/table\u003e\n\nWhenever the process should exit if the error is thrown.\n\n## Related\n\n- [`jneidel/api.jneidel.com`](https://github.com/jneidel/api.jneidel.com) - The api this module was built for. See for a usage example.\n\n## License\n\nMIT © [Jonathan Neidel](https://jneidel.com)\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjneidel%2Ferr-hndlr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjneidel%2Ferr-hndlr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjneidel%2Ferr-hndlr/lists"}