{"id":20645108,"url":"https://github.com/jesusgraterol/error-message-utils","last_synced_at":"2025-04-16T02:11:04.460Z","repository":{"id":238535113,"uuid":"796767154","full_name":"jesusgraterol/error-message-utils","owner":"jesusgraterol","description":"The error-message-utils package simplifies error management in your web applications and RESTful APIs. It ensures consistent and scalable handling of error messages, saving you time and effort. Moreover, it gives you the ability to assign custom error codes so all possible cases can be handled accordingly.","archived":false,"fork":false,"pushed_at":"2024-12-03T15:20:28.000Z","size":437,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T04:02:57.757Z","etag":null,"topics":["decoder","encoder","error","error-decoder","error-encoder","error-handling","error-management","error-utilities","error-utils","standard-error","stderr","utilities","utils"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/error-message-utils","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/jesusgraterol.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2024-05-06T15:34:00.000Z","updated_at":"2024-12-03T15:24:15.000Z","dependencies_parsed_at":"2024-06-03T16:34:07.171Z","dependency_job_id":"79438b8f-a363-48eb-8122-7343d9521435","html_url":"https://github.com/jesusgraterol/error-message-utils","commit_stats":null,"previous_names":["jesusgraterol/error-message-utils"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jesusgraterol%2Ferror-message-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jesusgraterol%2Ferror-message-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jesusgraterol%2Ferror-message-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jesusgraterol%2Ferror-message-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jesusgraterol","download_url":"https://codeload.github.com/jesusgraterol/error-message-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249183106,"owners_count":21226142,"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":["decoder","encoder","error","error-decoder","error-encoder","error-handling","error-management","error-utilities","error-utils","standard-error","stderr","utilities","utils"],"created_at":"2024-11-16T16:18:43.639Z","updated_at":"2025-04-16T02:11:04.454Z","avatar_url":"https://github.com/jesusgraterol.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Error Message Utils\n\nThe `error-message-utils` package simplifies error management in your web applications and RESTful APIs. It ensures consistent and scalable handling of error messages, saving you time and effort.  Moreover, it gives you the ability to assign custom error codes so all possible cases can be handled accordingly.\n\n\n\n\n\n\u003c/br\u003e\n\n## Getting Started\n\nInstall the package:\n```bash\nnpm install -S error-message-utils\n```\n\n### Examples\n\nEncoding an error:\n\n```typescript\nimport { encodeError } from 'error-message-utils';\n\nif (emailExists()) {\n  throw new Error(encodeError(\n    'The provided email is already in use.', \n    'EMAIL_EXISTS'\n  ));\n  // 'The provided email is already in use.{(EMAIL_EXISTS)}'\n}\n```\n\n\n\u003cbr/\u003e\n\nDecoding an error:\n\n```typescript\nimport { decodeError } from 'error-message-utils';\n\ndecodeError('The provided email is already in use.{(EMAIL_EXISTS)}');\n// {\n//   message: 'The provided email is already in use.',\n//   code: 'EMAIL_EXISTS'\n// }\n```\n\n\n\u003cbr/\u003e\n\nError messages can be extracted recursively from complex structures, including nested `cause` data properties from `Error` instances:\n\n```typescript\nimport { extractMessage } from 'error-message-utils';\n\nextractMessage(new Error('Top level error', {\n  cause: new Error('First nested cause', {\n    cause: new Error('Second nested cause'),\n  }),\n}));\n// 'Top level error; [CAUSE]: First nested cause; [CAUSE]: Second nested cause'\n\n\nextractMessage({ \n  message: { \n    err: { \n      message: 'This error message is nested deeply!'\n    } \n  } \n});\n// 'This error message is nested deeply!'\n```\n\n\n\u003cbr/\u003e\n\nIdentifying encoded errors:\n\n```typescript\nimport { isEncodedError, encodeError } from 'error-message-utils';\n\nisEncodedError('Some random unencoded error');\n// false\n\nisEncodedError(new Error('Some random unencoded error'));\n// false\n\nisEncodedError(encodeError('Some unknown error.', 'NASTY_ERROR'));\n// true\n\nisEncodedError(encodeError(new Error('Some unknown error.'), 'NASTY_ERROR'));\n// true\n```\n\n\n\n\n\u003cbr/\u003e\n\n## Types\n\n```typescript\n/**\n * Error Code\n * The code that is inserted when encoding an error. If none is provided or none can be extracted, it defaults to -1.\n */\ntype IErrorCode = string | number;\n\n/**\n * Decoded Error\n * The object obtained when an error is decoded. Keep in mind that if the error message or the code cannot be extracted for any reason, the default values will be set instead.\n */\ntype IDecodedError = {\n  message: string,\n  code: IErrorCode,\n};\n```\n\n\n\n\u003cbr/\u003e\n\n## Built With\n\n- TypeScript\n\n\n\n\n\u003cbr/\u003e\n\n## Running the Tests\n\n```bash\nnpm run test:unit\n```\n\n\n\n\n\n\u003cbr/\u003e\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n\n\n\n\n\n\u003cbr/\u003e\n\n## Deployment\n\nInstall dependencies:\n```bash\nnpm install\n```\n\n\nBuild the library:\n```bash\nnpm start\n```\n\n\nPublish to `npm`:\n```bash\nnpm publish\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjesusgraterol%2Ferror-message-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjesusgraterol%2Ferror-message-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjesusgraterol%2Ferror-message-utils/lists"}