{"id":19438645,"url":"https://github.com/geminiwind/jsonapierrors","last_synced_at":"2025-10-31T10:05:24.063Z","repository":{"id":35135057,"uuid":"211039950","full_name":"GeminiWind/JsonAPIErrors","owner":"GeminiWind","description":"A collection of Json API Errors","archived":false,"fork":false,"pushed_at":"2023-01-04T11:26:30.000Z","size":390,"stargazers_count":2,"open_issues_count":14,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-13T02:51:13.143Z","etag":null,"topics":["json-api"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/GeminiWind.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2019-09-26T08:32:47.000Z","updated_at":"2022-08-27T00:42:35.000Z","dependencies_parsed_at":"2023-01-15T14:45:24.675Z","dependency_job_id":null,"html_url":"https://github.com/GeminiWind/JsonAPIErrors","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeminiWind%2FJsonAPIErrors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeminiWind%2FJsonAPIErrors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeminiWind%2FJsonAPIErrors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeminiWind%2FJsonAPIErrors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GeminiWind","download_url":"https://codeload.github.com/GeminiWind/JsonAPIErrors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223968867,"owners_count":17233556,"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":["json-api"],"created_at":"2024-11-10T15:19:13.797Z","updated_at":"2025-10-31T10:05:19.043Z","avatar_url":"https://github.com/GeminiWind.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **JSON API Errors**\n\nJSON API Errors is a collection of popular errors which is format under of JSON API Specification. More detailed in [here](https://jsonapi.org/format/#error-objects)\n\n## Getting Started\n\n### Installation\nThe easiest way to install `json-api-error` is using NPM. If you have Node.js installed, it is most likely that you have NPM installed as well.\n\n```\n$ npm install json-api-error\n```\n\n### Usage\n\nAt the current implementation, `json-api-error` support the following common errors\n\n- `BadRequestError`\n- `UnauthorizedError`\n- `MalformedError`\n- `ForbiddenError`\n- `NotFoundError`\n- `MethodNotAllowedError`\n- `NotAcceptableError`\n- `RequestTimeoutError`\n- `UnsupportedMediaTypeError`\n- `InternalError`\n- `NotImplementedError`\n- `BadGatewayError`\n- `ServiceUnavailableError`\n- `GatewayTimeoutError`\n\n### Example\n\n### Error usage with simple detailed message\n\n```js\nimport { BadRequestError } from 'json-api-error';\n\nthrow new BadRequestError('Request is invalid');\n```\n\n### Error usage with options\n\n```\nimport { BadRequestError } from 'json-api-error';\n\nthrow new BadRequestError({\n    id: 'BadRequestError',\n    code: 'BadRequestError',\n    title: 'BadRequestError',\n    detail: 'The #/userName must be number'\n}));\n```\n\n### Error usage with customized your JsonApiError\n\n```js\nimport JsonApiError from 'json-api-error';\n\nthrow new JsonApiError({\n    id: 'RequestEntityTooLargeError',\n    status: '413',\n    code: 'RequestEntityTooLargeError',\n    title: 'RequestEntityTooLargeError',\n    detail: 'Request Entity Too Large'\n  });\n```\n\n### AggregateJsonApiError(errors, status)\n\n```js\nimport { AggregateJsonApiError } from 'json-api-error';\n\nthrow new AggregateJsonApiError([\n  new BadRequestError('Something went wrong'),\n  new BadRequestError('Request is valid')\n], 400);\n```\n\n### Express Middleware - JSON API Error Handler usage\n\n`json-api-error` also ships a Express middleware to handle these JSON API Errors. This middleware will catch JSON API Error and return response for your end-user as the following example format (including the status response):\n\n```js\n{\n  errors: [{\n    id: 'NotFoundError',\n    status: '404',\n    code: 'NotFoundError',\n    title: 'NotFoundError',\n    detail: 'Resource was not found'\n  }]\n}\n```\n\nTo use this, configure your Express app\n\n\n```js\nimport { jsonApiErrorHandler } from 'json-api-error/middlewares';\n\n\napp.use(jsonApiErrorHandler);\n\n```\n\n**Note:** For best practice, please place `jsonApiErrorHandler` below utilized middlewares.\n\n### Options\n\n| Properties  | Detail   | Type  |  Default Value  |\n|---|---|---|---|\n| id  | a unique identifier for this particular occurrence of the problem  | string  |  equal to error name |\n| links  | a links object, more detailed in [here](https://jsonapi.org/format/#error-objects) |  object | N/A |\n| status | the HTTP status code applicable to this problem, expressed as a string value  |  string | equal to HTTP code |\n| code |  an application-specific error code, expressed as a string value | string  | equal to error name |\n| title | a short, human-readable summary of the problem  | string  |  equal to error name |\n| detail | a human-readable explanation specific to this occurrence of the problem  | string  |  equal to error name |\n| source |  an object containing references to the source of the error, more detailed in [here](https://jsonapi.org/format/#error-objects) |  object | N/A |\n| meta | a meta object containing non-standard meta-information about the error.  | object  |  N/A |\n\n## LICENSE\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeminiwind%2Fjsonapierrors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeminiwind%2Fjsonapierrors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeminiwind%2Fjsonapierrors/lists"}