UNPKG

central-error-codes

Version:

Centralized error codes for SDK

120 lines (119 loc) 4.61 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ErrorCode = void 0; var fs = require("fs"); var path = require("path"); var ErrorCode = /** @class */ (function () { function ErrorCode() { } // Initialize error codes ErrorCode.initialize = function () { var _this = this; try { var modulePath_1 = path.dirname(require.resolve('central-error-codes/package.json')); var filePath = path.join(modulePath_1, 'dist/typescript/errors/error-codes.json'); var data = fs.readFileSync(filePath, 'utf-8'); this.errors = JSON.parse(data); Object.keys(this.errors).forEach(function (key) { if (typeof _this.errors[key] === 'string') { _this.errors[key] = _this.loadErrorFile(_this.errors[key], modulePath_1); } }); } catch (error) { console.error('Error loading error-codes.json:', error); } }; // Helper function to load an individual error file ErrorCode.loadErrorFile = function (filePath, modulePath) { try { var absolutePath = path.join(modulePath, 'dist/typescript/errors', filePath); var data = fs.readFileSync(absolutePath, 'utf-8'); return JSON.parse(data); } catch (error) { console.error("Error reading file at ".concat(filePath, ":"), error); return null; } }; // Merge all error categories into one single object ErrorCode.getAllErrorCodes = function () { var _this = this; var mergedErrors = {}; // Merge individual error categories into the mergedErrors object var errorCategories = [ 'GENERIC_ERROR', 'LLM_GW_ERROR', 'CMS_GW_ERROR', 'REVIEW_TOOL_ERROR', 'RECOMMENDATION_TOOL_ERROR', 'TOOL_SERVER_ERROR', 'MINERVAA_GENERIC_ERROR', 'DEEPEVAL_API_MASTER', 'MINERVAA_AI_MASTER', 'MINERVAA_DEEPEVAL_SYNTHESIZER_API', 'MINERVAA_EMAIL_CLIENT', , 'MINERVAA_KNOWLEDGE_HUB_API', 'MINERVAA_LLM_WRAPPER_API', 'MINERVAA_MONITORING_FRAMEWORK', 'MINERVAA_TOOL_SESSION_REPLAY', 'MINERVAA_TOOLS_API' ]; errorCategories.forEach(function (category) { if (_this.errors[category]) { Object.assign(mergedErrors, _this.errors[category]); } }); return mergedErrors; }; /** Returns selected error codes (e.g., GENERIC_ERROR, LLM_GW_ERROR) */ ErrorCode.getError = function () { return __assign({}, this.errors); }; /** Returns only GENERIC_ERROR codes */ ErrorCode.getGenericError = function () { var _a; return ((_a = this.errors) === null || _a === void 0 ? void 0 : _a.GENERIC_ERROR) || {}; }; /** Returns only LLM_GW_ERROR codes */ ErrorCode.getLLMGatewayError = function () { var _a; return ((_a = this.errors) === null || _a === void 0 ? void 0 : _a.LLM_GW_ERROR) || {}; }; /** Returns only CMS_GW_ERROR codes */ ErrorCode.getCMSGatewayError = function () { var _a; return ((_a = this.errors) === null || _a === void 0 ? void 0 : _a.CMS_GW_ERROR) || {}; }; /** Returns only REVIEW_TOOL_ERROR codes */ ErrorCode.getReviewToolKitError = function () { var _a; return ((_a = this.errors) === null || _a === void 0 ? void 0 : _a.REVIEW_TOOL_ERROR) || {}; }; /** Returns only RECOMMENDATION_TOOL_ERROR codes */ ErrorCode.getRecommendationToolError = function () { var _a; return ((_a = this.errors) === null || _a === void 0 ? void 0 : _a.RECOMMENDATION_TOOL_ERROR) || {}; }; /** Returns only TOOL_SERVER_ERROR codes */ ErrorCode.getToolServerError = function () { var _a; return ((_a = this.errors) === null || _a === void 0 ? void 0 : _a.TOOL_SERVER_ERROR) || {}; }; ErrorCode.errors = {}; return ErrorCode; }()); exports.ErrorCode = ErrorCode; // Initialize error codes on import ErrorCode.initialize();