{"id":17983489,"url":"https://github.com/techjacker/custom-errors","last_synced_at":"2025-03-25T19:32:36.985Z","repository":{"id":7872454,"uuid":"9245216","full_name":"techjacker/custom-errors","owner":"techjacker","description":"Custom Javascript Error Classes optimised for error logging","archived":false,"fork":false,"pushed_at":"2016-04-18T22:03:09.000Z","size":414,"stargazers_count":3,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-18T17:13:22.892Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/techjacker.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":"2013-04-05T16:17:23.000Z","updated_at":"2015-01-22T09:29:20.000Z","dependencies_parsed_at":"2022-09-24T05:11:01.724Z","dependency_job_id":null,"html_url":"https://github.com/techjacker/custom-errors","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techjacker%2Fcustom-errors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techjacker%2Fcustom-errors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techjacker%2Fcustom-errors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techjacker%2Fcustom-errors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/techjacker","download_url":"https://codeload.github.com/techjacker/custom-errors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222090823,"owners_count":16929472,"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":[],"created_at":"2024-10-29T18:17:23.804Z","updated_at":"2024-10-29T18:17:24.475Z","avatar_url":"https://github.com/techjacker.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Custom Error Classes\n\n[![Build Status](https://secure.travis-ci.org/techjacker/custom-errors.png)](http://travis-ci.org/techjacker/custom-errors)\n\n- All classes inherit from the abstract class (lib/abstract-error.js) inspired by [dustin senos's post](http://dustinsenos.com/articles/customErrorsInNode).\n- The abstract error class inherits from the in built error object.\n- All error classes exported in lib/main.js -\u003e index.js\n- Easy logging integration with express.js using the [log errors module](https://github.com/techjacker/log-errors)\n\n### App Error Classes (module.exports.general)\n\t1. ValidationError\n\t2. DatabaseError\n\n### Express Error Classes (module.exports.request)\n\t1. BadRequest = Bad Request Error (400)\n\t2. Unauthorized = Unauthorized Error (401)\n\t3. Forbidden = Forbidden Error (403)\n\t4. NotAcceptable Request Not Acceptable Error (406)\n\n## Sample Usage\n\n### 1. General Error Classes\n```JavaScript\nvar main \t\t\t= require('./../lib/main');\nvar ValidationError = main.general.ValidationError;\n\nvar msg \t = \"terrible input\",\n\tValError = new ValidationError(msg);\n\nconsole.log('ValError', ValError);\n```\n\nSTDOUT output:\n```Shell\nValError {\n\tname: 'Validation',\n\tlogLevel: 'warning',\n\tdoNotKill: undefined,\n\tresCode: undefined,\n\tmessage: 'not a valid date'\n}\n```\n\n### 2. Request Error Classes\n```JavaScript\nvar BadRequestError = main.request.BadRequest;\nvar msg = \"just an awful request\",\n\tReqError = new BadRequestError(msg);\n\nconsole.log('ReqError', ReqError);\n```\n\nSTDOUT output:\n```Shell\nReqError {\n\tname: 'BadRequest',\n\tlogLevel: 'warning',\n\tresCode: 400,\n\tmessage: 'just an awful request'\n}\n```\n\n## Using with Express.js\n\nEasy integration with the [log errors module](https://github.com/techjacker/log-errors)\n\n```JavaScript\nvar BadRequestError = require('customErrors').request.BadRequest;\nvar logErrors   = require('log-errors');\n\n// define some routes\napp.get('/some/route', function(req, res, next) {\n\tif ('error thrown') {\n\t\tnext(new BadRequestError('reason for the bad request being thrown'));\n\t}\n});\n\n//... catchall error middleware (put at very end beneath all routes)\napp.configure('development', function() {\n\n\t// wrap the logger if you need to do something\n\t// with the error before passing it to the logger\n    app.use(function(err, req, res, next) {\n\t\terr.resCode || (err.resCode = 400);\n        logErrors.development(err, req, res, next);\n    });\n});\n\napp.configure('production', function() {\n\t// defaults to sending 500 response if err.resCode is not set\n    app.use(logErrors.production);\n});\n```\n\n### Reference\n#### [Header status codes](http://en.wikipedia.org/wiki/List_of_HTTP_status_codes)\n\n#### log levels\n##### [Visionmedia Logging Module](https://github.com/visionmedia/log.js)\n\t0 EMERGENCY system is unusable\n\t1 ALERT action must be taken immediately\n\t2 CRITICAL the system is in critical condition\n\t3 ERROR error condition\n\t4 WARNING warning condition\n\t5 NOTICE a normal but significant condition\n\t6 INFO a purely informational message\n\t7 DEBUG messages to debug an application","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechjacker%2Fcustom-errors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechjacker%2Fcustom-errors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechjacker%2Fcustom-errors/lists"}