{"_id":"@code-net/errors","_rev":"13-e54d374ffbcad9c2e91dec225b527b45","name":"@code-net/errors","dist-tags":{"latest":"1.1.2"},"versions":{"1.0.0":{"name":"@code-net/errors","version":"1.0.0","author":{"name":"Bartosz Pasinski","email":"bartosz.pasinski@codenet.pl"},"license":"MIT","_id":"@code-net/errors@1.0.0","maintainers":[{"name":"pasi","email":"bartosz.pasinski@gmail.com"}],"dist":{"shasum":"00834e22cc91674340f47ed9fa0359d13a380c3f","tarball":"https://registry.npmjs.org/@code-net/errors/-/errors-1.0.0.tgz","fileCount":10,"integrity":"sha512-7Z/8e1tegR1Nwvm4r+/QT4wiFjzl41R4bHzarsdmF3hmK8eQ2W7lVvy3Gux7KIN2LGPadh54F3SugtyPQo614g==","signatures":[{"sig":"MEQCH1yGiqlnmf+ACI24JoG96uQImVsTo1X95QKrfPWbwgMCIQDgq4IM85HXmbzZ3QymU2cB0vw3uYVxSDpUJOibbriXOw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":6806},"main":"dist/index.js","type":"commonjs","types":"./dist/index.d.ts","gitHead":"cf41cdb18e57d5330f5dcf530b6f4b712cc76b06","scripts":{"build":"rm -rf ./dist && tsc -p tsconfig.lib.json"},"_npmUser":{"name":"pasi","email":"bartosz.pasinski@gmail.com"},"_npmVersion":"10.8.2","description":"This package contains application, domain and infrastructure layer errors. The idea is to provide a stable way to handle errors in a more structured way, allowing for better separation of concerns easier testing.","directories":{},"_nodeVersion":"20.18.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/errors_1.0.0_1747943651905_0.4667405231224351","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@code-net/errors","version":"1.0.1","author":{"name":"Bartosz Pasinski","email":"bartosz.pasinski@codenet.pl"},"license":"MIT","_id":"@code-net/errors@1.0.1","maintainers":[{"name":"pasi","email":"bartosz.pasinski@gmail.com"}],"dist":{"shasum":"94a631c329bcde149d44aeb9c0bfd4580f5c480c","tarball":"https://registry.npmjs.org/@code-net/errors/-/errors-1.0.1.tgz","fileCount":12,"integrity":"sha512-PPazXGs1ffNZ81Ozbzxxvg11HqdRLjLZGcCKKNKvZxmzRjf6lxtpjZzYS4em4s4fUoINUzvRTMbUuKBhDNjxnw==","signatures":[{"sig":"MEYCIQCEMK8c2Cve/SO+ux4olt7KX4XYxoPu6TTp8pSuUivIEQIhAOIQ887JE6UImbGT3AdqDFoAW0wo92AupR+fVJWvD5Fm","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":11076},"main":"dist/index.js","type":"commonjs","types":"./dist/index.d.ts","gitHead":"cf41cdb18e57d5330f5dcf530b6f4b712cc76b06","scripts":{"build":"rm -rf ./dist && tsc -p tsconfig.lib.json"},"_npmUser":{"name":"pasi","email":"bartosz.pasinski@gmail.com"},"_npmVersion":"10.8.2","description":"This package contains application, domain and infrastructure layer errors. The idea is to provide a stable way to handle errors in a more structured way, allowing for better separation of concerns easier testing and translation between layers.","directories":{},"_nodeVersion":"20.18.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/errors_1.0.1_1747945613558_0.8557971414039387","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@code-net/errors","version":"1.0.2","_id":"@code-net/errors@1.0.2","maintainers":[{"name":"pasi","email":"bartosz.pasinski@gmail.com"}],"dist":{"shasum":"4171a85f489f934aa63676b05735dc966567f712","tarball":"https://registry.npmjs.org/@code-net/errors/-/errors-1.0.2.tgz","fileCount":17,"integrity":"sha512-rRNhHZzeP+5vvQ+gqDb3E4XyaSy7fId0IMqAmS5T9z+D+AYADWg4Brp85bqb1LCfDfSgRoNnwnPAo69L2GG5VA==","signatures":[{"sig":"MEYCIQDvYWKylJ+hTF+SUBc0kU9P/X4j44PcXoN9MFF5o7sYPwIhALJpTbfsn47rLyrE7cCbtZcUtdPMcuuV8PKML3feP/kB","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":14074},"main":"./src/index.js","type":"commonjs","types":"./src/index.d.ts","gitHead":"42ee562ba009dda55cab229fafecc31c25f67f69","_npmUser":{"name":"pasi","email":"bartosz.pasinski@gmail.com"},"_npmVersion":"10.8.2","description":"This package contains application, domain and infrastructure layer errors. The idea is to provide a stable way to handle errors in a more structured way, allowing for better separation of concerns easier testing and translation between layers.","directories":{},"_nodeVersion":"20.18.1","dependencies":{"tslib":"^2.3.0"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/errors_1.0.2_1749327066115_0.42329284320891025","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"@code-net/errors","version":"1.0.3","_id":"@code-net/errors@1.0.3","maintainers":[{"name":"pasi","email":"bartosz.pasinski@gmail.com"}],"homepage":"https://github.com/CodeNet-pl/NodeJS#readme","bugs":{"url":"https://github.com/CodeNet-pl/NodeJS/issues"},"dist":{"shasum":"f765561422856029e00ad5147f129b27464bf672","tarball":"https://registry.npmjs.org/@code-net/errors/-/errors-1.0.3.tgz","fileCount":16,"integrity":"sha512-1PQjMzoFRG4venjLny/Rrn3sHRGvHpOvqm/2LhuG+oCyMe/sFJWXnpQJhhHzdHwYOi31LSryNTDWNXozRxJT6w==","signatures":[{"sig":"MEQCIEn+aY5l/U1RqueZizAudY+BYu+VKec3oc/qeOGqV2QYAiAH3qVAQc4j0YhG49V5/Pb+7BnjgnngsXulfyplkzkvRg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":10240},"main":"./src/index.js","type":"commonjs","types":"./src/index.d.ts","gitHead":"0a67a5085799d65d524e5c779f78cb00f11efc4a","_npmUser":{"name":"pasi","email":"bartosz.pasinski@gmail.com"},"repository":{"url":"git+https://github.com/CodeNet-pl/NodeJS.git"},"_npmVersion":"10.8.2","directories":{},"_nodeVersion":"20.18.1","dependencies":{"tslib":"^2.3.0"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/errors_1.0.3_1749482307948_0.6881073573000092","host":"s3://npm-registry-packages-npm-production"}},"1.0.4":{"name":"@code-net/errors","version":"1.0.4","_id":"@code-net/errors@1.0.4","maintainers":[{"name":"pasi","email":"bartosz.pasinski@gmail.com"}],"homepage":"https://github.com/CodeNet-pl/NodeJS#readme","bugs":{"url":"https://github.com/CodeNet-pl/NodeJS/issues"},"dist":{"shasum":"acf2decbd29e68cbb9502a68be293c24a28275cb","tarball":"https://registry.npmjs.org/@code-net/errors/-/errors-1.0.4.tgz","fileCount":17,"integrity":"sha512-9wefBkh9m/iAc48B8EIn/A/CzUWqmNN30GeswZw99nJOacqnxFxRC3WIf4a7ygBDHOgDDdqW7e8Wa1gbeuIehQ==","signatures":[{"sig":"MEUCIFGalc8D4iOAVuWXSHVAHEAKX+8cAYDHB8aiWreNgH51AiEA6cEKAzWD4u9iyhX2X0FOSGkWh2/tcO+61N+8FprRBT8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":14147},"main":"./src/index.js","type":"commonjs","types":"./src/index.d.ts","gitHead":"0a67a5085799d65d524e5c779f78cb00f11efc4a","_npmUser":{"name":"pasi","email":"bartosz.pasinski@gmail.com"},"repository":{"url":"git+https://github.com/CodeNet-pl/NodeJS.git"},"_npmVersion":"10.8.2","description":"This package contains application, domain and infrastructure layer errors. The idea is to provide a stable way to handle errors in a more structured way, allowing for better separation of concerns easier testing and translation between layers.","directories":{},"_nodeVersion":"20.18.1","dependencies":{"tslib":"^2.3.0"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/errors_1.0.4_1749484846477_0.09935381953652511","host":"s3://npm-registry-packages-npm-production"}},"1.0.5":{"name":"@code-net/errors","version":"1.0.5","_id":"@code-net/errors@1.0.5","maintainers":[{"name":"pasi","email":"bartosz.pasinski@gmail.com"}],"homepage":"https://github.com/CodeNet-pl/NodeJS#readme","bugs":{"url":"https://github.com/CodeNet-pl/NodeJS/issues"},"dist":{"shasum":"1e221f6639ed1690b804c763bd0d47ae22b4a6d3","tarball":"https://registry.npmjs.org/@code-net/errors/-/errors-1.0.5.tgz","fileCount":17,"integrity":"sha512-sdTvWaH1NZrG0X76yOpnCjBLDrt/V7JpgdCTfgjvpSqIFySoNyMsLh2qpF6pabF0D/cDdjzXjcaVm8WkTtZMrQ==","signatures":[{"sig":"MEYCIQDXauCKydgcjgt8Z7f13tvSScjtEZi3KOaVCJ8V+nNPfgIhAOkAZvCohNOm9IUJIM5ThJ5N7aHkRm9ggnbUw1CvX1bk","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":14147},"main":"./src/index.js","type":"commonjs","types":"./src/index.d.ts","gitHead":"271304fd1998393265da155b66e2afcb78c96351","_npmUser":{"name":"pasi","email":"bartosz.pasinski@gmail.com"},"repository":{"url":"git+https://github.com/CodeNet-pl/NodeJS.git"},"_npmVersion":"10.8.2","description":"This package contains application, domain and infrastructure layer errors. The idea is to provide a stable way to handle errors in a more structured way, allowing for better separation of concerns easier testing and translation between layers.","directories":{},"_nodeVersion":"20.18.1","dependencies":{"tslib":"^2.3.0"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/errors_1.0.5_1749485727620_0.9180792181211597","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@code-net/errors","version":"1.1.0","_id":"@code-net/errors@1.1.0","maintainers":[{"name":"pasi","email":"bartosz.pasinski@gmail.com"}],"homepage":"https://github.com/CodeNet-pl/NodeJS#readme","bugs":{"url":"https://github.com/CodeNet-pl/NodeJS/issues"},"dist":{"shasum":"69fdf7b0cf38a195f0cde5e6a63b08acc4ff8bb9","tarball":"https://registry.npmjs.org/@code-net/errors/-/errors-1.1.0.tgz","fileCount":17,"integrity":"sha512-gf1f4Wjiw3L5J7fPQT7oynuqUwZ/vDm8tQY3HV2WLurNHldIBgspwgXoUpgHcrs6ThYT8AL9mh4cA4+CYI7y4g==","signatures":[{"sig":"MEYCIQChWWKfG3gD0zfmm/uXeMO4NPwO6tmgr80TcrudAOydWQIhAJ+Vt7AIiQY9y10xcpFdFb1/foqy7oBdO8jHfBEzvYod","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":14147},"main":"./src/index.js","type":"commonjs","types":"./src/index.d.ts","gitHead":"ab8c56244086b0dbd231b5b6d4fb2cba198dec3a","_npmUser":{"name":"pasi","email":"bartosz.pasinski@gmail.com"},"repository":{"url":"git+https://github.com/CodeNet-pl/NodeJS.git"},"_npmVersion":"10.8.2","description":"This package contains application, domain and infrastructure layer errors. The idea is to provide a stable way to handle errors in a more structured way, allowing for better separation of concerns easier testing and translation between layers.","directories":{},"_nodeVersion":"20.18.1","dependencies":{"tslib":"^2.3.0"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/errors_1.1.0_1749486773595_0.18695557977911204","host":"s3://npm-registry-packages-npm-production"}},"1.1.1":{"name":"@code-net/errors","version":"1.1.1","_id":"@code-net/errors@1.1.1","maintainers":[{"name":"pasi","email":"bartosz.pasinski@gmail.com"}],"homepage":"https://github.com/CodeNet-pl/NodeJS#readme","bugs":{"url":"https://github.com/CodeNet-pl/NodeJS/issues"},"dist":{"shasum":"bced7095a97efbd6054552d0b4d25adf31e874d9","tarball":"https://registry.npmjs.org/@code-net/errors/-/errors-1.1.1.tgz","fileCount":17,"integrity":"sha512-e1Zfr9lnexTqaMFcsPocjNJUtuBbtEKifc/dcti2r8SAmNtYODEUU0JihvbSydC36Vj+8XAeoAeFg/W1TiYbyw==","signatures":[{"sig":"MEYCIQC8NLOJKC83HoYXTX8BYwcBNCIyTOFoPg7AyfbN3TdqigIhAPdWfC2KLIOcb/MuN/Q8HnrRoOGaqnQzxWRGXnrGRf3U","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":14147},"main":"./src/index.js","type":"commonjs","types":"./src/index.d.ts","gitHead":"1fb9f8db8c228bd6ea8e5405fc79f387cb8021fb","_npmUser":{"name":"pasi","email":"bartosz.pasinski@gmail.com"},"repository":{"url":"git+https://github.com/CodeNet-pl/NodeJS.git"},"_npmVersion":"10.8.2","description":"This package contains application, domain and infrastructure layer errors. The idea is to provide a stable way to handle errors in a more structured way, allowing for better separation of concerns easier testing and translation between layers.","directories":{},"_nodeVersion":"20.18.1","dependencies":{"tslib":"^2.3.0"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/errors_1.1.1_1749581764513_0.5290389514648797","host":"s3://npm-registry-packages-npm-production"}},"1.1.2":{"name":"@code-net/errors","version":"1.1.2","author":{"url":"https://dev.pasi.pl","name":"Bartosz Pasinski","email":"bartosz.pasinski@gmail.com"},"_id":"@code-net/errors@1.1.2","maintainers":[{"name":"pasi","email":"bartosz.pasinski@gmail.com"}],"homepage":"https://github.com/CodeNet-pl/NodeJS#readme","bugs":{"url":"https://github.com/CodeNet-pl/NodeJS/issues"},"dist":{"shasum":"6f0b3c3ef924a2d7e24e2ba6bb6f5db465a0a866","tarball":"https://registry.npmjs.org/@code-net/errors/-/errors-1.1.2.tgz","fileCount":17,"integrity":"sha512-mLk2Ki3JS8a1cp2l0zQRHoWp4/88MWIR4fEN/aK14xMh3F/TME2cRbYgHYnUl8Z9i9skd7KibgihC4XRVOC/4w==","signatures":[{"sig":"MEYCIQDtq/vQHagyakTQRIzGpC5af6K1WuqVDCQSM6cyL4qDYgIhAOex7jAmZJaAYDifwER5aiMjOAdZaEpWTadHAr/uyYQV","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":14273},"main":"./src/index.js","type":"commonjs","_from":"file:code-net-errors-1.1.2.tgz","types":"./src/index.d.ts","_npmUser":{"name":"pasi","email":"bartosz.pasinski@gmail.com"},"_resolved":"/tmp/6adac9a2d9dcbe3be759b77faf93a48a/code-net-errors-1.1.2.tgz","_integrity":"sha512-mLk2Ki3JS8a1cp2l0zQRHoWp4/88MWIR4fEN/aK14xMh3F/TME2cRbYgHYnUl8Z9i9skd7KibgihC4XRVOC/4w==","repository":{"url":"git+https://github.com/CodeNet-pl/NodeJS.git"},"_npmVersion":"10.8.2","description":"This package contains application, domain and infrastructure layer errors. The idea is to provide a stable way to handle errors in a more structured way, allowing for better separation of concerns easier testing and translation between layers.","directories":{},"_nodeVersion":"20.18.1","dependencies":{"tslib":"^2.3.0"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/errors_1.1.2_1749888218096_0.7849210819277108","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2025-05-22T19:54:11.800Z","modified":"2025-09-24T15:45:52.318Z","1.0.0":"2025-05-22T19:54:12.091Z","1.0.1":"2025-05-22T20:26:53.737Z","1.0.2":"2025-06-07T20:11:06.284Z","1.0.3":"2025-06-09T15:18:28.135Z","1.0.4":"2025-06-09T16:00:46.658Z","1.0.5":"2025-06-09T16:15:27.803Z","1.1.0":"2025-06-09T16:32:53.794Z","1.1.1":"2025-06-10T18:56:04.715Z","1.1.2":"2025-06-14T08:03:38.269Z"},"bugs":{"url":"https://github.com/CodeNet-pl/NodeJS/issues"},"homepage":"https://github.com/CodeNet-pl/NodeJS#readme","repository":{"url":"git+https://github.com/CodeNet-pl/NodeJS.git"},"description":"This package contains application, domain and infrastructure layer errors. The idea is to provide a stable way to handle errors in a more structured way, allowing for better separation of concerns easier testing and translation between layers.","maintainers":[{"name":"pasi","email":"bartosz.pasinski@gmail.com"}],"readme":"# Errors\n\nThis package contains application, domain and infrastructure layer errors. The idea is to provide a stable way to handle errors in a more structured way, allowing for better separation of concerns easier testing and translation between layers.\n\nNo more generic 500 errors in your application, no more `Error` objects with no information about what went wrong.\n\n## Application Errors\n\nApplication errors are used to indicate errors that occur during the execution of the application. They are typically used to indicate errors that are not related to the domain logic, such as network errors, database errors, etc.\n\nExamples:\n\n- `NotFound` - Indicates that the requested resource was not found;\n- `AccessDenied` / `PermissionDenied` - Indicates that the user does not have permission to access the requested resource;\n- `InvalidValue` - Indicates that the provided value is invalid;\n- `InvalidState` - Indicates that the application is in an invalid state;\n- `InternalError` - Indicates that an internal error occurred;\n- `NotImplemented` - Indicates that the requested feature is not implemented;\n- `OperationTimeout` - Indicates that the operation timed out;\n- `ServiceUnavailable` - Indicates that the service is unavailable;\n- `ValidationError` - Indicates that the provided value is invalid;\n\n## Domain Errors\n\nDomain errors are used to indicate errors that occur during the execution of the domain logic. They are typically used to indicate errors that are related to the domain logic, such as validation errors, business rule violations, etc.\n\nExamples:\n\n- `BusinessRuleViolation` / `InvalidState` - Indicates that a business rule was violated;\n- `InvalidValue` - Indicates that the provided value is invalid;\n- `EntityNotFound` - Indicates that the requested domain entity was not found;\n\n## Infrastructure Errors\n\nInfrastructure errors are used to indicate errors that occur during the execution of the infrastructure, such as network errors, database errors, etc.\n\nExamples:\n\n- `PersistenceError` - Indicates that a persistence error occurred;\n- `ConcurrencyError` - Indicates that a concurrency error occurred;\n\n## Why?\n\nUsually all errors in nodejs ecosystem are scoped to HTTP layer, this makes it hard to write HTTP agnostic code. This package is designed to provide a way to handle errors in a more structured way, allowing for better separation of concerns and easier testing.\n\n## Usage\n\n```ts\nimport { NotFound } from '@code-net/errors';\n\nthrow new NotFound('User not found');\n```\n\nRe-throwing errors:\n\n```ts\nimport { NotFound } from '@code-net/errors';\n\ntry {\n  // logic\n} catch (e) {\n  throw new NotFound('User not found', { cause: e });\n}\n```\n\n### Mapping between layers\n\nMapping domain layer to application layer:\n\n```ts\nimport { mapDomainToApplicationError, EntityNotFound } from '@code-net/errors';\n\nmapDomainToApplicationError(new EntityNotFound('User not found')); // NotFound with cause User not found\nmapDomainToApplicationError(new BusinessRuleViolation('Limit exceeded')); // Conflict with cause Limit exceeded\n```\n\nMapping infrastructure layer to application layer:\n\n```ts\nimport { mapInfrastructureToApplicationError, PersistenceError } from '@code-net/errors';\nimport { NotFound } from '@code-net/errors';\nimport { InternalError } from '@code-net/errors';\n\nmapInfrastructureToApplicationError(new ConcurrencyError('Optimistic lock failed')); // Conflict with cause Optimistic lock failed\n```\n\n### Translating into HTTP errors\n\nYou have to register the error mapper in your application. This is usually done in the main file of your application.\n\n```ts\nimport { mapErrorToApplicationError } from '@code-net/errors';\n\nconst applicationError = mapErrorToApplicationError(error); // ApplicationError\n\nif (error instanceof NotFound) {\n  res.setStatus(404).json({\n    message: error.message,\n  });\n}\n// ...\n```\n\n## License\n\nThis project is licensed under the MIT License.\n","readmeFilename":"README.md"}