{"id":18940295,"url":"https://github.com/donejs/donejs-error-format","last_synced_at":"2026-03-23T07:30:17.225Z","repository":{"id":57215092,"uuid":"124285426","full_name":"donejs/donejs-error-format","owner":"donejs","description":"Generate HTML from an error message, for dev mode","archived":false,"fork":false,"pushed_at":"2019-06-20T16:54:43.000Z","size":20,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-31T23:34:20.830Z","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/donejs.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":"2018-03-07T19:40:04.000Z","updated_at":"2019-06-19T19:11:45.000Z","dependencies_parsed_at":"2022-08-24T21:01:26.054Z","dependency_job_id":null,"html_url":"https://github.com/donejs/donejs-error-format","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donejs%2Fdonejs-error-format","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donejs%2Fdonejs-error-format/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donejs%2Fdonejs-error-format/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donejs%2Fdonejs-error-format/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/donejs","download_url":"https://codeload.github.com/donejs/donejs-error-format/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239939066,"owners_count":19721768,"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-08T12:21:48.861Z","updated_at":"2026-03-23T07:30:17.193Z","avatar_url":"https://github.com/donejs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# donejs-error-format\n\n[![Build Status](https://travis-ci.org/donejs/donejs-error-format.svg?branch=master)](https://travis-ci.org/donejs/donejs-error-format)\n[![npm version](https://badge.fury.io/js/donejs-error-format.svg)](http://badge.fury.io/js/donejs-error-format)\n\nAn error formatter for Errors that are emitted by [done-ssr](https://github.com/donejs/done-ssr).\n\n\u003cimg src=\"https://user-images.githubusercontent.com/361671/37160048-4c2f266c-22bd-11e8-885d-687bb6428860.png\" alt=\"donejs-error-format example\" style=\"max-width:100%;\"\u003e\n\n# Install\n\n```shell\nnpm install donejs-error-format --save\n```\n\n# Usage\n\nIf you are using done-serve, it already uses donejs-error-format internally. If you use done-ssr or done-ssr-middleware, you can use this module to format your error messages.\n\n## done-ssr\n\n```js\nconst errorFormat = require(\"donejs-error-format\");\nconst ssr = require(\"done-ssr\");\n\nconst render = ssr({ config: __dirname + \"/package.json\" });\n\nfunction app(request, response) {\n\t// More stuff here, obviously, like static assets, etc.\n\n\tlet stream = render(request);\n\n\tstream.on(\"error\", function(error){\n\t\tlet parts = errorFormat.extract(error);\n\t\tlet html = errorFormat.html(parts);\n\n\t\tconsole.error(error);\n\n\t\tresponse.writeHead(200, { type: \"text/html\" });\n\t\tresponse.end(html);\n\t});\n\n\tstream.pipe(response);\n}\n\nrequire(\"http\").createServer(app).listen(8080);\n```\n\n## done-ssr-middleware\n\n```js\nconst express = require(\"express\");\nconst errorFormat = require(\"donejs-error-format\");\nconst ssr = require(\"done-ssr-middleware\");\n\nconst app = express();\n\napp.use(express.static(__dirname + \"/public\"));\n\napp.use(ssr({ config: __dirname + \"/package.json!npm\" }));\n\n\n// The last middleware should be the error handler\napp.use(function(error, request, response, next) {\n\tlet parts = errorFormat.extract(error);\n\tlet html = errorFormat.html(parts);\n\n\tconsole.error(error);\n\n\tresponse.type(\"html\").end(html);\n});\n```\n\n# API\n\n## .extract(error)\n\nThis function takes an [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) and returns an object with parts extracted. This is used to pass into `.html()` and other formatting functions (currently there is only HTML).\n\n## .html(parts)\n\nThis function is used to generate formatted HTML. It takes a __parts__ object that comes from using `.extract`.\n\n```js\nlet parts = errorFormat.extract(error);\nlet html = errorFormat.html(parts);\n```\n\n### .html(parts, options)\n\nThe second signature is like the first but takes an __options__ object. The options are:\n\n* __liveReload__: This can either be the boolean `true` or an object that provides the port like: `{ port: 4044 }`. By default the port __8012__ is used (which is the default in DoneJS apps). You only need to set this option if you are using an alternative port in your development server.\n\nEnabling the live-reload script:\n\n```js\nlet parts = errorFormat.extract(error);\nlet html = errorFormat.html(parts, {\n\tliveReload: true\n})\n```\n\nOr with a port:\n\n```js\nlet parts = errorFormat.extract(error);\nlet html = errorFormat.html(parts, {\n\tliveReload: {\n\t\tport: 4044\n\t}\n})\n```\n\n# License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdonejs%2Fdonejs-error-format","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdonejs%2Fdonejs-error-format","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdonejs%2Fdonejs-error-format/lists"}