{"id":20767012,"url":"https://github.com/binded/http-errors-express","last_synced_at":"2025-05-11T08:34:10.003Z","repository":{"id":57268142,"uuid":"57927655","full_name":"binded/http-errors-express","owner":"binded","description":"Express middleware for handling errors generated or compatible with http-errors.","archived":false,"fork":false,"pushed_at":"2017-06-15T00:32:29.000Z","size":37,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-01-03T03:39:20.797Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/binded.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-05-02T23:28:09.000Z","updated_at":"2018-11-15T02:13:37.000Z","dependencies_parsed_at":"2022-09-02T02:50:16.110Z","dependency_job_id":null,"html_url":"https://github.com/binded/http-errors-express","commit_stats":null,"previous_names":["blockai/http-errors-express"],"tags_count":1,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Fhttp-errors-express","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Fhttp-errors-express/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Fhttp-errors-express/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Fhttp-errors-express/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binded","download_url":"https://codeload.github.com/binded/http-errors-express/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225030753,"owners_count":17409942,"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-11-17T11:27:16.218Z","updated_at":"2024-11-17T11:27:16.849Z","avatar_url":"https://github.com/binded.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# http-errors-express\n\n[![Build Status](https://travis-ci.org/binded/http-errors-express.svg?branch=master)](https://travis-ci.org/binded/http-errors-express)\n\n[Express](http://expressjs.com) middleware for handling errors generated or compatible with the [http-errors](https://github.com/jshttp/http-errors) module. Sends errors to client using JSON, for example:\n\n```javascript\nimport createError from 'http-errors'\n\n// ...\n\napp.post('/pay', (req, res, next) =\u003e {\n  next(createError(402, 'Your balance is too low.', {\n    detail: {\n      currentBalance: 100,\n      price: 150,\n    },\n  }))\n})\n\n// ...\n```\n\nwould send the following JSON response payload to the client:\n\n```json\n{\n  \"error\": {\n    \"name\": \"PaymentRequiredError\",\n    \"message\": \"Your balance is too low.\",\n    \"detail\": {\n      \"currentBalance\": 100,\n      \"price\": 150\n    }\n  }\n}\n```\n\nSee [./test/index.js](./test/index.js) for more examples.\n\n## Install\n\n```\nnpm install --save http-errors-express\n```\n\n## Usage\n\n**httpErrors(opts)**\n\nAll options are optional.\n\n- `opts.before` function with `(err, req, isExposed, cb)` signature that can\n    be used to log errors for example. Defaults to logging with `console.error`\n    for unexposed errors. Can ignore the `cb` and instead return a\n    promise.\n- `opts.formatError` function with `(err, req, isExposed)` signature which formats errors\n    before passing to `res.json`\n\nReturns an Express middleware. The HTTP response is only sent after the\n`before` function's callback is called. This is useful if we want to\ninclude an error ID received from a remote error logging service (e.g.\nservice) as part of the response.\n\nIf an exposed error has a `detail` property, it will by default be\nincluded as part of the JSON response.\n\n```javascript\nimport express from 'express'\nimport httpErrors from 'http-errors-express'\n\nconst app = express()\n// ...\n// This should be the last middleware\napp.use(httpErrors())\n```\n\nSee [./test/index.js](./test/index.js) for more examples.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinded%2Fhttp-errors-express","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinded%2Fhttp-errors-express","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinded%2Fhttp-errors-express/lists"}