{"id":24383366,"url":"https://github.com/firstandthird/hapi-friendly-errors","last_synced_at":"2025-03-12T17:20:22.809Z","repository":{"id":54130152,"uuid":"43262935","full_name":"firstandthird/hapi-friendly-errors","owner":"firstandthird","description":"Hapi plugin to show a friendly error page","archived":false,"fork":false,"pushed_at":"2021-03-08T20:02:26.000Z","size":64,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-04T09:40:25.058Z","etag":null,"topics":["hapi-plugin","hapi-v17"],"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/firstandthird.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":"2015-09-27T20:10:28.000Z","updated_at":"2021-03-08T20:02:27.000Z","dependencies_parsed_at":"2022-08-13T07:10:19.424Z","dependency_job_id":null,"html_url":"https://github.com/firstandthird/hapi-friendly-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/firstandthird%2Fhapi-friendly-errors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-friendly-errors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-friendly-errors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-friendly-errors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/firstandthird","download_url":"https://codeload.github.com/firstandthird/hapi-friendly-errors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243258922,"owners_count":20262362,"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":["hapi-plugin","hapi-v17"],"created_at":"2025-01-19T10:14:20.753Z","updated_at":"2025-03-12T17:20:22.783Z","avatar_url":"https://github.com/firstandthird.png","language":"JavaScript","readme":"# hapi-friendly-errors\n\n[![Coverage Status](https://coveralls.io/repos/github/firstandthird/hapi-friendly-errors/badge.svg)](https://coveralls.io/github/firstandthird/hapi-friendly-errors)\n\nA small library for displaying very friendly errors in hapi.\n\n## Installation\n\n```\nnpm install hapi-friendly-errors\n```\n\n## Basic Usage\n\n Just register like a normal hapi plugin:\n\n```js\nawait server.register({\n  plugin: require('hapi-friendly-errors')\n});\n```\n\nIf you have a broken route like this:\n```js\nserver.route({\n  path: '/foobar',\n  method: 'GET',\n  handler(request, reply) {\n    throw Boom.notFound('this is not foobar');\n  }\n});\n```\n\nwhen you fetch the _/foobar_ route, you will get back a 404 code with the following:\n\n```html\n\u003ch1\u003eThere was an error\u003c/h1\u003e\n\u003ch2\u003eNot Found: this is not foobar\u003c/h2\u003e\n```\n\n## Custom Views\n\nhapi-friendly-errors will also work with your view engine if you want a custom error page.  For example\nif you have a [handlebars](https://handlebarsjs.com/) template named _error-page_:\n\n```html\n\u003ch1\u003eUnfortunately You Have Encountered an Error\u003c/h1\u003e\n\n\u003cb\u003eError\u003c/b\u003e: {{error}}\n\u003cb\u003eReason\u003c/b\u003e: {{message}}\n\u003cb\u003eAdditional Stuff\u003c/b\u003e: {{protocol}}{{domain}}\n```\n\n```js\nawait server.register({\n  plugin: require('hapi-friendly-errors'),\n  options: {\n    view: 'error-page'\n  }\n});\nserver.views({\n  engines: { html: require('handlebars') },\n  context: {\n    protocol: 'http://',\n    domain: 'foobar.com'\n  }\n});\n```\n\nNow fetching the _/foobar_ route will give:\n\n```html\n\u003ch1\u003eUnfortunately You Have Encountered an Error\u003c/h1\u003e\n\n\u003cb\u003eError\u003c/b\u003e: Not Found\n\u003cb\u003eReason\u003c/b\u003e: this is not foobar\n\u003cb\u003eAdditional Stuff\u003c/b\u003e: http://foobar.com\n```\n\n## JSON\n\nhapi-friendly-errors will skip HTML and just return a JSON object when requests contain the _Accept: application/json_ header:\n```js\n{ statusCode: 403, error: 'Forbidden', message: 'Not Authorized' }\n```\n\n\n## Plugin Options\n\n  You can pass these when you register the plugin\n\n- __errorBlacklist__\n\n  A regular expression passed as a string. Routes matching this regular expression will be ignored by hapi-friendly-errors\n\n- __logErrors__\n\n  When true will log output any time there is a 500 Server error.\n\n- __url__\n\n  You can also specify a local URL to render and return HTML errors, when this happens the statusCode, error and message will be passed as query parameters:\n\n  ```js\n  await server.register({\n    plugin: require('hapi-friendly-errors'),\n    options: {\n      url: '/error'\n    }\n  });\n\n  server.route({\n    path: '/foobar',\n    method: 'GET',\n    handler(request, reply) {\n      throw Boom.notFound('this is not foobar');\n    }\n  });\n\n  server.route({\n    path: '/error',\n    method: 'GET',\n    handler(request, h) {\n      const query = request.query;\n      return `\n      \u003ch1\u003eAn Error Handled by Route\u003c/h1\u003e\n      \u003cb\u003eError\u003c/b\u003e ${query.statusCode} ${query.error.}\n      \u003cb\u003eMessage\u003c/b\u003e ${query.message}\n      `;\n    }\n  });\n  ```\n\n  Now when you call the _/foobar_ route you will get back:\n  ```HTML\n  \u003ch1\u003eAn Error Handled by Route\u003c/h1\u003e\n  \u003cb\u003eError\u003c/b\u003e 404 Not Found\n  \u003cb\u003eMessage\u003c/b\u003e this is not foobar!\n  ```\n\n- __context__\n\n  An object that will be merged with the context and passed to the rendering engine. If specified, _error_, _message_ and _statusCode_ will be overridden.\n  ```js\n  await server.register({\n    plugin: require('hapi-friendly-errors'),\n    options: {\n      context: {\n        data1: 'some more data',\n        error: 'A Server Error'\n      }\n    }\n  });\n  ```\n\n  Now errors will look something like:\n\n  ```html\n  \u003ch1\u003eThere was an error\u003c/h1\u003e\n  \u003ch2\u003eA Server Error: this is not foobar\u003c/h2\u003e\n  ```\n\n- __view__\n\n  Name of the view to render, if not specified then view will default to:\n\n  ```js\n  `\u003ch1\u003eThere was an error\u003c/h1\u003e\u003ch2\u003e${context.error}: ${context.message}\u003c/h2\u003e`\n  ```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstandthird%2Fhapi-friendly-errors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffirstandthird%2Fhapi-friendly-errors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstandthird%2Fhapi-friendly-errors/lists"}