{"id":29903142,"url":"https://github.com/ezzabuzaid/rfc-7807-problem-details","last_synced_at":"2025-08-01T16:49:34.042Z","repository":{"id":57678805,"uuid":"490682366","full_name":"ezzabuzaid/rfc-7807-problem-details","owner":"ezzabuzaid","description":"Typescript implementation of RFC 7807","archived":false,"fork":false,"pushed_at":"2022-12-13T20:05:44.000Z","size":1585,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-26T23:34:41.077Z","etag":null,"topics":["deno","nodejs","problem-details","rfc-7807","typescript"],"latest_commit_sha":null,"homepage":"https://docs.page/ezzabuzaid/rfc-7807-problem-details","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/ezzabuzaid.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":"2022-05-10T12:16:00.000Z","updated_at":"2024-02-09T22:48:02.000Z","dependencies_parsed_at":"2023-01-28T14:35:11.927Z","dependency_job_id":null,"html_url":"https://github.com/ezzabuzaid/rfc-7807-problem-details","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/ezzabuzaid/rfc-7807-problem-details","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezzabuzaid%2Frfc-7807-problem-details","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezzabuzaid%2Frfc-7807-problem-details/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezzabuzaid%2Frfc-7807-problem-details/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezzabuzaid%2Frfc-7807-problem-details/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ezzabuzaid","download_url":"https://codeload.github.com/ezzabuzaid/rfc-7807-problem-details/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezzabuzaid%2Frfc-7807-problem-details/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268264481,"owners_count":24222509,"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","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["deno","nodejs","problem-details","rfc-7807","typescript"],"created_at":"2025-08-01T16:49:18.848Z","updated_at":"2025-08-01T16:49:34.013Z","avatar_url":"https://github.com/ezzabuzaid.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Typescript implementation of [RFC 7807](https://datatracker.ietf.org/doc/html/rfc7807)\ninspired from [Hellang ProblemDetails](https://www.nuget.org/packages/Hellang.Middleware.ProblemDetails)\n\n\n## Install\n```bash\nnpm i rfc-7807-problem-details\n# Using Yarn\nyarn add rfc-7807-problem-details\n```\n\n\n## Problem details options\n\n- typePrefix - [Reference](https://datatracker.ietf.org/doc/html/rfc7807#section-3.1)\n- contentTypes - response content type, defaults to \"application/problem+json\"\n- mapStatusCode - a function that creates default problem details in case there's no mapping for the current error or the `predicate` mapping didn't pass\n- appendCacheHeaders - a function the add no cache response header\n- includeExceptionDetails - a function that determines whether to include exception details or not.\n- exceptionDetailsPropertyName - the property name that will have the error stack trace, defaults to `exceptionDetails`\n\n### Cache headers\n\nBy default these headers will be added\n\n```txt\n\"cache-control\": \"no-cache, no-store, must-revalidate\"\n\"pragma\": \"no-cache\"\n\"etag\": \"0\"\n\"expires\": \"0\"\n```\n\nYou can modify this behaviour by changing appendCacheHeaders option\n\n```typescript\n// Default function\noptions.appendCacheHeaders = (setHeader) =\u003e {\n\tsetHeader(\"cache-control\", \"no-cache, no-store, must-revalidate\");\n\tsetHeader(\"pragma\", \"no-cache\");\n\tsetHeader(\"etag\", \"0\");\n\tsetHeader(\"expires\", \"0\");\n};\n\n// Do not add any cache header\noptions.appendCacheHeaders = (setHeader) =\u003e {};\n\n// Add custom cache headers\noptions.appendCacheHeaders = (setHeader) =\u003e {\n\tsetHeader(\"cache-control\", \"no-cache, no-store, must-revalidate\");\n\tsetHeader(\"pragma\", \"no-cache\");\n\tsetHeader(\"etag\", \"0\");\n\tsetHeader(\"expires\", \"0\");\n\tsetHeader(\"Last-Modified\", \"Wed, 21 Oct 2015 07:28:00 GMT\"); // This line\n};\n```\n\n## Framework support\n\nThe library support Koa.js and express.js out of the box\n\n- Express\n\n```typescript\nimport express from \"express\";\nimport { problemDetailsMiddleware } from \"rfc-7807-problem-details\";\nconst app = express();\n\n// Should be added at the last of the middleware chain\napp.use(problemDetailsMiddleware.express());\n```\n\n[Complete example](https://docs.page/ezzabuzaid/rfc-7807-problem-details/expressjs)\n\n- Koa\n\n```typescript\nimport Koa from \"koa\";\nimport { problemDetailsMiddleware } from \"rfc-7807-problem-details\";\nconst app = new Koa();\n\n// Should be added at the start of the middleware chain\napp.use(problemDetailsMiddleware.koa());\n```\n\n[Complete example](https://docs.page/ezzabuzaid/rfc-7807-problem-details/koa)\n\n- Deno - Oak\n\n```typescript\nimport { Application } from \"https://deno.land/x/oak/mod.ts\";\nimport {\n\tProblemDetailsException,\n\tProblemDetailsOptions,\n\tProblemDetailsSetup,\n} from \"https://esm.sh/rfc-7807-problem-details\";\nconst app = new Application();\n\napp.use(async (ctx, next) =\u003e {\n\t// set your options before constructing ProblemDetailsSetup\n\tconst options = new ProblemDetailsOptions();\n\toptions.typePrefix = `https://example.com/probs/out-of-credit`;\n\n\tconst setup = new ProblemDetailsSetup(options);\n\n\treturn async (context: any, next: any) =\u003e {\n\t\ttry {\n\t\t\tawait next();\n\t\t} catch (error) {\n\t\t\toptions.appendCacheHeaders((name, value) =\u003e\n\t\t\t\tctx.response.headers.set(name, value)\n\t\t\t);\n\n\t\t\tconst problem = setup.prepareProblemDetails(error, context);\n\t\t\tctx.response.headers.set(\"content-type\", options.contentTypes);\n\t\t\tcontext.status = problem.status;\n\t\t\tcontext.body = problem;\n\t\t}\n\t};\n});\n\napp.use(async (ctx, next) =\u003e {\n\tswitch (ctx.request.url.pathname) {\n\t\tcase \"/example/throw\":\n\t\t\tthrow new ProblemDetailsException({\n\t\t\t\ttype: \"cannot-proceed\",\n\t\t\t\tstatus: 400,\n\t\t\t\ttitle: \"You cannot proceed.\",\n\t\t\t});\n\t\tdefault:\n\t\t\tctx.response.body = \"Hello World\";\n\t\t\tbreak;\n\t}\n\tawait next();\n});\n\nawait app.listen({ port: 8000 });\n```\n\nIf you'd like to support custom framework take a look at the source code to see how you can do it.\n\nFor more examples check the **demo** directory.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezzabuzaid%2Frfc-7807-problem-details","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fezzabuzaid%2Frfc-7807-problem-details","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezzabuzaid%2Frfc-7807-problem-details/lists"}