{"id":13789873,"url":"https://github.com/yfrans/elysia-http-error","last_synced_at":"2025-10-08T02:13:25.912Z","repository":{"id":194532183,"uuid":"691106799","full_name":"yfrans/elysia-http-error","owner":"yfrans","description":"Easy http error handling in Elysia.","archived":false,"fork":false,"pushed_at":"2024-07-18T06:19:29.000Z","size":20,"stargazers_count":11,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-31T00:53:00.810Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/yfrans.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-09-13T14:08:14.000Z","updated_at":"2025-05-12T22:14:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"096f0531-00bf-4276-ad2f-6e12607f4e60","html_url":"https://github.com/yfrans/elysia-http-error","commit_stats":null,"previous_names":["yfrans/elysia-http-error"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yfrans/elysia-http-error","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yfrans%2Felysia-http-error","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yfrans%2Felysia-http-error/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yfrans%2Felysia-http-error/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yfrans%2Felysia-http-error/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yfrans","download_url":"https://codeload.github.com/yfrans/elysia-http-error/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yfrans%2Felysia-http-error/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278877092,"owners_count":26061381,"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-10-08T02:00:06.501Z","response_time":56,"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":[],"created_at":"2024-08-03T22:00:34.023Z","updated_at":"2025-10-08T02:13:25.886Z","avatar_url":"https://github.com/yfrans.png","language":"TypeScript","funding_links":[],"categories":["Plugins"],"sub_categories":[],"readme":"# Elysia HTTP Error\n\nThrow HTTP errors from Elysia handlers.\n\n# Usage\n\nInstall the package:\n\n`bun add elysia-http-error`\n\nThen use `httpError()` in Elysia pipeline as follow:\n\n```ts\nconst app = new Elysia().use(httpError());\n```\n\nBy default, this module will return a structured message with the error details.\n\nIf you need the message to be a simple string, use:\n\n```ts\nreturnStringOnly: true;\n```\n\nwhen initializing `httpError()`.\n\nAnother option is to write a custom error message formatter using:\n\n```ts\ncustomFormatter: (err: HttpError) =\u003e any;\n```\n\nwhich allows a full control over the returned error object.\n\nFor example:\n\n```ts\ncustomFormatter: (err) =\u003e `Oh no... we got an error ${err.statusCode}!`;\n```\n\nIn order to use the HttpError class and throw an error, the `HttpError` decorator must be added to the pipeline:\n\n```ts\nconst app = new Elysia().use(httpErrorDecorator).get(\"/\", ({ HttpError }) =\u003e {\n  throw HttpError.BadRequest(\"Something went wrong...\");\n});\n```\n\nThe HttpError constructor receive the following parameters:\n\n```ts\nerror: string (error message, optional)\nerrorData: any (more error details, optional)\n```\n\nFor example, when using OTP validation and the user is asking for a new OTP while the OTP is still valid, the error can contain the message and the time left for the OTP so the client can display a proper message and sync the time displayed to the user:\n\n```ts\nthrow HttpError.Conflict(\"OTP is still valid\", {\n  timeLeft: otpExpireTime - Date.now(),\n});\n```\n\n# Some important notes\n\nThe plugin initializer must be called when initializing Elysia and before any other handler that use this plugin.\n\nWhen using dependecy injection and sub-modules, the decorator must be used in the sub-module definition in order to get full type support (see https://elysiajs.com/patterns/dependency-injection.html#dependency-injection)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyfrans%2Felysia-http-error","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyfrans%2Felysia-http-error","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyfrans%2Felysia-http-error/lists"}