{"_id":"@anhkhoakz/express-http-errors","name":"@anhkhoakz/express-http-errors","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@anhkhoakz/express-http-errors","description":"Express-friendly HTTP errors with typed status factories.","version":"1.0.0","repository":{"url":"https://git.sr.ht/~anhkhoakz/express-http-errors"},"module":"./dist/index.js","type":"module","license":"MIT","main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"devDependencies":{"@types/bun":"latest","@types/node":"^26.0.1","typescript":"^5.9.3"},"sideEffects":false,"scripts":{"generate":"bun run scripts/generate.ts","typecheck":"tsgo --noEmit","build":"tsgo","test":"bun test","pack:check":"npm pack --dry-run","publish:public":"npm publish --access public"},"publishConfig":{"access":"public"},"_id":"@anhkhoakz/express-http-errors@1.0.0","homepage":"https://git.sr.ht/~anhkhoakz/express-http-errors#readme","_nodeVersion":"26.4.0","_npmVersion":"11.17.0","dist":{"integrity":"sha512-bpYPPbaq8RLUE0ZOzbmCMpXKTOxUAilQKv2YWSWtsfs9ZpbYO2hAHILS6ymFnzeZ72l5bVKa8uuzcBUBfwc9bg==","shasum":"44777df1fefc58ccc4fc17089acd1ada97923ece","tarball":"https://registry.npmjs.org/@anhkhoakz/express-http-errors/-/express-http-errors-1.0.0.tgz","fileCount":9,"unpackedSize":165433,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCuHNKHgfB01rdKBHPXmO+7RxENNfGGOscVjmFHoNc0nwIgK8t5cGeErllSg1NvjivJ4R6+REeDuiU/tNOKrsnOOu0="}]},"_npmUser":{"name":"anhkhoakz","email":"outgrow_footwear345@slmail.me"},"directories":{},"maintainers":[{"name":"anhkhoakz","email":"outgrow_footwear345@slmail.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/express-http-errors_1.0.0_1782784584750_0.69414861916104"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-30T01:56:24.508Z","1.0.0":"2026-06-30T01:56:24.887Z","modified":"2026-06-30T01:56:25.203Z"},"maintainers":[{"name":"anhkhoakz","email":"outgrow_footwear345@slmail.me"}],"description":"Express-friendly HTTP errors with typed status factories.","homepage":"https://git.sr.ht/~anhkhoakz/express-http-errors#readme","repository":{"url":"https://git.sr.ht/~anhkhoakz/express-http-errors"},"license":"MIT","readme":"# @anhkhoakz/http-errors\n\nExpress-friendly HTTP errors with typed status factories.\n\nThe package exports a single `HttpError` class with:\n\n- `err.status` and `err.statusCode` for Express middleware\n- generated helpers like `HttpError.notFound()` and `HttpError[404]()`\n- a `HttpError.success()` alias for `200 OK`\n- optional `details`, `headers`, `cause`, and `expose` metadata\n- zero runtime dependencies\n\n## Install\n\n```bash\nnpm install @anhkhoakz/http-errors\n```\n\n## Quick Start\n\n```ts\nimport express from \"express\";\nimport { HttpError } from \"@anhkhoakz/http-errors\";\n\nconst app = express();\n\napp.get(\"/users/:id\", async (req, res) => {\n  if (req.params.id === \"0\") {\n    throw HttpError.notFound(\"User not found\", {\n      details: { userId: req.params.id },\n    });\n  }\n\n  res.json({ id: req.params.id });\n});\n\napp.use((err, req, res, next) => {\n  if (!HttpError.is(err)) {\n    return next(err);\n  }\n\n  if (err.headers) {\n    res.set(err.headers);\n  }\n\n  res.status(err.status).json({\n    error: err.message,\n    details: err.expose ? err.details : undefined,\n  });\n});\n```\n\nExpress 5 treats rejected async handlers as errors automatically. Error\nmiddleware must still be registered last and use the four-argument signature\n`(err, req, res, next)`.\n\n## API\n\n### `HttpError`\n\n```ts\nimport { HttpError } from \"@anhkhoakz/http-errors\";\n\nthrow HttpError.badRequest(\"Invalid payload\");\nthrow HttpError[401](\"Missing token\");\nthrow HttpError.success();\n```\n\nEach instance includes:\n\n```ts\ntype HttpErrorInstance = {\n  message: string;\n  status: number;\n  statusCode: number;\n  statusText: string;\n  expose: boolean;\n  headers?: Readonly<Record<string, string | readonly string[]>>;\n  details?: unknown;\n  cause?: unknown;\n};\n```\n\n### `HttpError.from(status, ...)`\n\nCreate an error when the status is only known at runtime.\n\n```ts\nconst status = 429 as const;\nconst error = HttpError.from(status, \"Rate limit exceeded\");\n```\n\n### `HttpError.is(value)`\n\nRuntime guard for custom middleware.\n\n```ts\nif (HttpError.is(err)) {\n  console.log(err.status, err.message);\n}\n```\n\n### `HttpError.isStatusCode(value)`\n\nCheck whether a number is a generated status code.\n\n```ts\nif (HttpError.isStatusCode(input)) {\n  throw HttpError.from(input);\n}\n```\n\n### `HttpError.getStatus(code)`\n\nRead generated metadata for a status code.\n\n```ts\nconst status = HttpError.getStatus(404);\n\nstatus.name;\nstatus.constant;\nstatus.comment.description;\nstatus.comment.doc;\n```\n\n## Types\n\n```ts\nimport type {\n  HttpErrorHeaders,\n  HttpErrorOptions,\n  HttpErrorStatusCode,\n  HttpErrorStatusConstant,\n  HttpErrorStatusName,\n} from \"@anhkhoakz/http-errors\";\n```\n\n## Development\n\n```bash\nbun install\nbun run generate\nbun run typecheck\nbun test\nbun run build\n```\n","readmeFilename":"README.md","_rev":"1-601b104f236bb0d9b3c4c467761a7213"}