{"name":"@swagger-api/apidom-error","version":"1.0.0-beta.37","author":"Vladimír Gorej <vladimir.gorej@gmail.com>","license":"Apache-2.0","_id":"@swagger-api/apidom-error@1.0.0-beta.37","maintainers":[{"name":"swagger-api","email":"apiteam@swagger.io"}],"dist":{"shasum":"56fedb5b9344b325295c798eae21d1c4ba0e8be8","tarball":"http://registry-npm.ywwl.com/@swagger-api/apidom-error/download/@swagger-api/apidom-error-1.0.0-beta.37.tgz","fileCount":23,"integrity":"sha512-goMIrcF02RFMW9uAfT0jWkp9gDNMOPqA2NJgb4bsEoBQL9uSXNnIMUEV3jF0fH4ZIanyqsar4ygznIKHC73Fdw==","signatures":[{"sig":"MEYCIQCKpk6cq2/hhsJDa553nht1gBgq4pzfeeV+8+0zVVgVggIhAIsip+jPDl7mMr8ELK4p/3/MkdSo+N0PU6h3joJNuv5P","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":70152,"size":16887,"noattachment":false,"key":"/@swagger-api/apidom-error/-/@swagger-api/apidom-error-1.0.0-beta.37.tgz"},"main":"./src/index.cjs","type":"module","types":"./types/apidom-error.d.ts","unpkg":"./dist/apidom-error.browser.min.js","exports":{"types":"./types/apidom-error.d.ts","import":"./src/index.mjs","require":"./src/index.cjs"},"gitHead":"6c04248d4c60b79542e4ef957170cc48c6889445","scripts":{"lint":"eslint ./","test":"npm run build:es && cross-env BABEL_ENV=es babel test --out-dir test --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward' && cross-env NODE_ENV=test mocha","build":"npm run clean && run-p --max-parallel ${CPU_CORES:-2} typescript:declaration build:es build:cjs build:umd:browser","clean":"rimraf --glob 'src/**/*.mjs' 'src/**/*.cjs' 'test/**/*.mjs' ./dist ./types","prepack":"copyfiles -u 3 ../../LICENSES/* LICENSES && copyfiles -u 2 ../../NOTICE .","build:es":"cross-env BABEL_ENV=es babel src --out-dir src --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward'","lint:fix":"eslint ./ --fix","postpack":"rimraf NOTICE LICENSES","build:cjs":"cross-env BABEL_ENV=cjs babel src --out-dir src --extensions '.ts' --out-file-extension '.cjs' --root-mode 'upward'","build:umd:browser":"cross-env BABEL_ENV=browser webpack --config config/webpack/browser.config.js --progress","typescript:check-types":"tsc --noEmit","typescript:declaration":"copyfiles -u 1 'src/**/*.d.ts' ./types && tsc -p tsconfig.declaration.json && api-extractor run -l -c ./config/api-extractor/api-extractor.json"},"_npmUser":{"name":"swagger-api","email":"apiteam@swagger.io"},"repository":{"url":"git+https://github.com/swagger-api/apidom.git","type":"git"},"_npmVersion":"lerna/8.2.2/node@v22.14.0+x64 (linux)","description":"Backward compatible custom ApiDOM errors with causes.","directories":{},"sideEffects":false,"_nodeVersion":"22.14.0","dependencies":{"@babel/runtime-corejs3":"^7.20.7"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/apidom-error_1.0.0-beta.37_1747060197771_0.8972094613297057","host":"s3://npm-registry-packages-npm-production"},"readme":"# @swagger-api/apidom-error\n\n`apidom-error` provides several error classes in support of [Joyent's Best Practices for Error Handling in Node.js](http://web.archive.org/web/20150221074228/http://www.joyent.com/developers/node/design/errors).\nThese error classes should be used as a superclass for all **operational errors**.\nOperational errors represent run-time problems experienced by correctly-written programs.\n\nError classes from `apidom-error` handle complexities of extending native Error class\nand support [error chaining](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause)\nin backward and forward compatible way.\n\n## Base errors\n\nBase errors are meant to directly be thrown by ApiDOM code or to be extended\nto form custom error hierarchies.\n\n### ApiDOMError\n\nBasic error class that can be easily extended and form error chains.\n\n```js\nimport { ApiDOMError } from '@swagger-api/apidom-error';\n\nconst error1 = new ApiDOMError('error message'); // basic error\nconst error2 = new ApiDOMError('error message', { cause: new Error('cause') }); // error chain\n```\n\n### ApiDOMStructuredError\n\nError class that is based on `ApiDOMError` and allows to assign arbitrary data properties to its instances.\n\n```js\nimport { ApiDOMStructuredError } from '@swagger-api/apidom-error';\n\nconst error1 = new ApiDOMStructuredError('error message', { cause: new Error('cause') }); // just like ApiDOMError\n\nconst error2 = new ApiDOMStructuredError('error message', {\n  prop1: 'value1',\n  prop2: 3,\n})\nerror2.prop1; // => 'value1'\nerror2.prop2; // => 3\n```\n\nAlthough structured error class gives convenience by assigning arbitrary properties\nit's highly recommended to extend `ApiDOMStructuredError` class and create public properties\nexplicitly.\n\n```typescript\nimport { ApiDOMStructuredError, ApiDOMErrorOptions } from '@swagger-api/apidom-error';\n\ninterface StructuredErrorOptions extends ApiDOMErrorOptions {\n  readonly prop1: string;\n  readonly prop2: number;\n}\n\nclass PropError extends ApiDOMStructuredError {\n  public readonly  prop1: string;\n  public readonly prop2: number;\n\n  constructor(message?: string, options?: StructuredErrorOptions) {\n    super(message, options)\n    if (typeof options !== 'undefined') {\n      this.prop1 = options.prop1;\n      this.prop2 = options.prop2;\n    }\n  }\n}\n```\n\n### ApiDOMAggregateError\n\n`ApiDOMAggregateError` can be easily extended and represents instance of an error when\nseveral errors need to be wrapped in a single error. It is thrown when multiple errors\nneed to be reported by an operation. Supports error chaining as well.\n\n```js\nimport { ApiDOMAggregateError } from '@swagger-api/apidom-error';\n\nconst error1 = new Error('error1');\nconst error2 = new Error('error2');\nconst cause = new Error('optional cause');\n\nconst aggregateError = new ApiDOMAggregateError([error1, error2], 'aggregate error', {\n  cause,\n});\n```\n\nThis class is based on native [AggregateError], and due to the fact that JavaScript\nclasses don't support multiple inheritance, it cannot also be based on `ApiDOMError`.\nNevertheless, for convenience, following will work:\n\n```js\nimport { ApiDOMAggregateError, ApiDOMError } from '@swagger-api/apidom-error';\n\nconst aggregateError = new ApiDOMAggregateError([]);\naggregateError instanceof ApiDOMError; // => true\naggregateError instanceof AggregateError; // => true\n```\n\n## Generic custom errors\n\nGeneric custom errors represents custom errors that are generic enough\nto be used across ApiDOM monorepo packages and are not specific to any\nparticular ApiDOM package.\n\n### UnsupportedOperationError\n\nThis error class that is based on `ApiDOMError`. Thrown to indicate that the requested operation is not supported.\n\n```js\nimport { UnsupportedOperationError } from '@swagger-api/apidom-error';\n\nconst error = new UnsupportedOperationError('error message');\n```\n\n### NotImplementedError\n\nError class that is based on `UnsupportedOperationError` and. It is thrown to indicate that a block\nof code has not been implemented. This exception provides a more semantically rich description\nof the problem than base `ApiDOMError`.\n\n```js\nimport { NotImplementedError } from '@swagger-api/apidom-error';\n\nconst error = new NotImplementedError('error message');\n```\n\n\n","publish_time":1747060197976,"_cnpm_publish_time":1747060197976,"dist-tags":{"latest":"1.14.0","v1.11-maintenance":"1.11.6"}}