{"id":28252521,"url":"https://github.com/censkh/sendable-error","last_synced_at":"2026-02-14T11:34:55.828Z","repository":{"id":57356602,"uuid":"285887900","full_name":"Censkh/sendable-error","owner":"Censkh","description":"Composable errors to simplify creating useful failure responses for APIs","archived":false,"fork":false,"pushed_at":"2025-03-09T10:39:30.000Z","size":564,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-12T20:01:57.653Z","etag":null,"topics":["api","backend","error","express","typescript"],"latest_commit_sha":null,"homepage":"","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/Censkh.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-08-07T17:42:41.000Z","updated_at":"2025-03-09T10:39:34.000Z","dependencies_parsed_at":"2023-11-07T16:25:52.592Z","dependency_job_id":"3704b606-4b53-4344-afe9-0bd3994a1d57","html_url":"https://github.com/Censkh/sendable-error","commit_stats":{"total_commits":21,"total_committers":1,"mean_commits":21.0,"dds":0.0,"last_synced_commit":"3213715b428a4e600582df7055ddc009d5780e69"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Censkh/sendable-error","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Censkh%2Fsendable-error","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Censkh%2Fsendable-error/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Censkh%2Fsendable-error/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Censkh%2Fsendable-error/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Censkh","download_url":"https://codeload.github.com/Censkh/sendable-error/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Censkh%2Fsendable-error/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262950293,"owners_count":23389638,"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":["api","backend","error","express","typescript"],"created_at":"2025-05-19T16:15:55.287Z","updated_at":"2026-02-14T11:34:55.760Z","avatar_url":"https://github.com/Censkh.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [sendable-error](https://github.com/Censkh/sendable-error/) \u0026middot; [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Censkh/style-composer/blob/master/LICENSE) [![npm version](https://img.shields.io/npm/v/sendable-error.svg?style=flat)](https://www.npmjs.com/package/sendable-error)\n\nComposable errors to simplify creating useful failure responses for APIs\n\n`SendableErrors` provide built-in support for:\n- An easy to use builder interface to construct errors\n- A unified way to send your errors as a JSON response\n- Error codes to easily identify error types on the client side\n- Public and private messages \u0026 details so your APIs don't leak technical information yet retaining verbose logging\n- Trace IDs allow you to identify specific errors and allows user's to point you in the right direction when they encounter a bug\n- A customizable logger interface\n\n\n```js\nimport { SendableError } from \"sendable-error\";\n\ntry {\n  throw new SendableError({\n    status: 400,\n    code: \"validation/missing-required\",\n    message: \"Missing required field 'id'\",\n    public: true,\n    details: {\n      field: \"id\"\n    }\n  })\n} catch (error) {\n  return SendableError.of(error).toResponse();\n}\n```\n\nResponse with status code `400`:\n\n```json\n{\n  \"code\": \"validation/missing-required\",\n  \"message\": \"Missing required field 'id'\",\n  \"traceId\": \"8ab9c56a-90d1-5e71-b67a-d6b725837802\",\n  \"details\": {\n    \"field\": \"id\"\n  }\n}\n```\n\n## Getting Started\n\n```bash\nnpm i sendable-error\n```\n\n### Throwing Errors\n\nCreating a new error from scratch:\n\n```js\n throw new SendableError({\n  code: CODE_MISSING_REQUIRED,\n  message: \"Missing required field 'id'\",\n  public: true,\n  details: {\n    field: \"id\",\n  },\n});\n```\n\nOr provide a cause for the error:\n\n```js\nthrow new SendableError({\n  code: CODE_DATABASE_ERROR,\n  cause: error,\n});\n```\n\nOr even transform an error from elsewhere into a `SendableError`:\n\n```js\nthrow SendableError.of(error, {\n  code: CODE_DATABASE_ERROR\n});\n```\n\n### Sending Errors\n\n#### Express\n\n```js\napp.use((error, req, res, next) =\u003e {\n  SendableError.of(error).send(res);\n});\n```\n\n#### WinterTC Compatible\n\n```typescript\nexport const handler = async (request: Request) =\u003e {\n  try {\n    // do something that might throw\n  } catch (error) {\n    return SendableError.of(error).toResponse();\n  }\n}\n```\n\n#### Others\n\n```typescript\ntry {\n  // do something that might throw\n} catch (error) {\n  const responseBody = SendableError.of(error).toResponseBody();\n  /* send responseBody */\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcenskh%2Fsendable-error","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcenskh%2Fsendable-error","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcenskh%2Fsendable-error/lists"}