{"id":17706181,"url":"https://github.com/fernandomoraes/common-exceptions","last_synced_at":"2025-03-31T05:26:19.570Z","repository":{"id":57204326,"uuid":"76743891","full_name":"fernandomoraes/common-exceptions","owner":"fernandomoraes","description":"common exceptions for nodejs","archived":false,"fork":false,"pushed_at":"2016-12-17T21:06:27.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-07T04:07:26.290Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fernandomoraes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-17T19:55:45.000Z","updated_at":"2023-03-10T10:42:43.000Z","dependencies_parsed_at":"2022-09-18T00:51:01.599Z","dependency_job_id":null,"html_url":"https://github.com/fernandomoraes/common-exceptions","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fernandomoraes%2Fcommon-exceptions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fernandomoraes%2Fcommon-exceptions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fernandomoraes%2Fcommon-exceptions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fernandomoraes%2Fcommon-exceptions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fernandomoraes","download_url":"https://codeload.github.com/fernandomoraes/common-exceptions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246420661,"owners_count":20774359,"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-24T23:07:11.547Z","updated_at":"2025-03-31T05:26:19.553Z","avatar_url":"https://github.com/fernandomoraes.png","language":"JavaScript","readme":"common-exceptions\n=========\n\nCommon exceptions to help handle easily exceptions in nodejs application\n\n## Installation\n\n`npm install --save common-exceptions`\n\n## Usage\n\n```javascript\nvar exceptions = require('common-exceptions');\nvar EntityNotFoundException = exceptions.EntityNotFoundException;\n\ntry {\n  foo();\n} catch (err) {\n  console.log(err instanceof EntityNotFoundException); //logs true\n}\n\nfunction foo() {\n  throw new EntityNotFoundException('Not found entity with id 2');\n}\n```\n\n## Exceptions\n\nCurrently there are the following exceptions for use:\n\n* EntityNotFoundException\n* ValidationException\n* IllegalArgumentException\n\n## Examples\n\n### Global express exception handler\n\n```javascript\nvar app = require('express').app();\nvar ValidationException = require('common-exceptions').ValidationException;\n\napp.post('/users', (req, res) =\u003e {\n    let user = req.body;\n    if (user.age \u003c= 18) {\n      throw new ValidationException('users must be over 18 years old!');\n    }\n});\n\napp.use((err, req, res, next) =\u003e {\n  if (err instanceof ValidationException) {\n    res.status(422).send({ message: err.message });\n  }\n});\n```\n\n## TODO\n\n* Add tests\n* Allow to register new exceptions in runtime\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffernandomoraes%2Fcommon-exceptions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffernandomoraes%2Fcommon-exceptions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffernandomoraes%2Fcommon-exceptions/lists"}