UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

1 lines 1.71 kB
{"version":3,"file":"lucid-error.mjs","names":[],"sources":["../../../src/utils/errors/lucid-error.ts"],"sourcesContent":["import logger from \"../../libs/logger/index.js\";\n\n/**\n * The LucidError class should be used to throw errors in functions that sit outside of API request lifecycle. This class will log the error and optionally kill the process.\n * @class\n * @extends Error\n * @param {string} data.message - The error message\n * @param {string} [data.scope] - Used to identify the scope of the logged error\n * @param {boolean} [data.kill] - If true, the process will exit with code 1\n * @returns {void}\n * @example\n * throw new LucidError({\n * message: \"Cannot set a value to a read-only property\",\n * scope: \"plugin-name\",\n * kill: true,\n * });\n */\nclass LucidError extends Error {\n\tscope?: string;\n\tkill?: boolean;\n\tconstructor(data: {\n\t\tmessage: string;\n\t\tscope?: string;\n\t\tkill?: boolean;\n\t\tdata?: Record<string, unknown>;\n\t}) {\n\t\tsuper(data.message);\n\t\tthis.scope = data.scope;\n\t\tthis.kill = data.kill;\n\n\t\tlogger.error({\n\t\t\terror: this,\n\t\t\tevent: \"lucid.error.thrown\",\n\t\t\tmessage: \"Lucid error thrown\",\n\t\t\tscope: this.scope,\n\t\t\tdata: {\n\t\t\t\t...(data.data ?? {}),\n\t\t\t\terrorMessage: this.message,\n\t\t\t},\n\t\t});\n\n\t\tif (this.kill) process.exit(1);\n\t}\n}\n\nexport default LucidError;\n"],"mappings":"2CAiBA,IAAM,EAAN,cAAyB,KAAM,CAC9B,MACA,KACA,YAAY,EAKT,CACF,MAAM,EAAK,OAAO,EAClB,KAAK,MAAQ,EAAK,MAClB,KAAK,KAAO,EAAK,KAEjB,EAAO,MAAM,CACZ,MAAO,KACP,MAAO,qBACP,QAAS,qBACT,MAAO,KAAK,MACZ,KAAM,CACL,GAAI,EAAK,MAAQ,CAAC,EAClB,aAAc,KAAK,OACpB,CACD,CAAC,EAEG,KAAK,MAAM,QAAQ,KAAK,CAAC,CAC9B,CACD"}