UNPKG

okta-mcp-server

Version:

Model Context Protocol (MCP) server for Okta API operations with support for bulk operations and caching

139 lines 4.56 kB
export class ErrorSimulator { config; defaultScenarios = [ { code: 401, message: 'Unauthorized', errorCode: 'E0000004', errorSummary: 'Authentication failed', errorLink: 'E0000004', errorId: 'oaeY-3I7_CuGXBsze6KkLmmGw', }, { code: 403, message: 'Forbidden', errorCode: 'E0000006', errorSummary: 'You do not have permission to perform the requested action', errorLink: 'E0000006', errorId: 'oaeaBauDp6H9rvMRfWS3Irmew', }, { code: 404, message: 'Not Found', errorCode: 'E0000007', errorSummary: 'Resource not found', errorLink: 'E0000007', errorId: 'oaeFi4nzLTO9K7OFvB98HvXvA', }, { code: 429, message: 'Too Many Requests', errorCode: 'E0000047', errorSummary: 'API call exceeded rate limit', errorLink: 'E0000047', errorId: 'oaewq0oPm9XKI0H2p1YD3m2HA', }, { code: 500, message: 'Internal Server Error', errorCode: 'E0000009', errorSummary: 'An internal server error has occurred', errorLink: 'E0000009', errorId: 'oaeWVOnFxDHHZrI4hEAKmDM8g', }, { code: 503, message: 'Service Unavailable', errorCode: 'E0000048', errorSummary: 'Service temporarily unavailable', errorLink: 'E0000048', errorId: 'oaezCGgCkmG6AGD_vBTPkmhSg', }, ]; constructor(config = { enabled: true, errorRate: 0.02, // 2% error rate by default }) { this.config = { ...config, scenarios: config.scenarios || this.defaultScenarios, specificErrors: config.specificErrors || new Map(), }; } shouldError(path) { if (!this.config.enabled) return false; // Check for path-specific errors first if (path && this.config.specificErrors?.has(path)) { return true; } return Math.random() < this.config.errorRate; } generateError(path) { if (!this.shouldError(path)) return null; // Check for path-specific error if (path && this.config.specificErrors?.has(path)) { return this.config.specificErrors.get(path); } // Return random error scenario const scenarios = this.config.scenarios || this.defaultScenarios; return scenarios[Math.floor(Math.random() * scenarios.length)] || null; } // Configure specific paths to always error setPathError(path, scenario) { this.config.specificErrors?.set(path, scenario); } clearPathError(path) { this.config.specificErrors?.delete(path); } // Simulate specific error scenarios simulateAuthError() { return { code: 401, message: 'Unauthorized', errorCode: 'E0000004', errorSummary: 'Invalid token provided', errorLink: 'E0000004', errorId: this.generateErrorId(), }; } simulateValidationError(field, value) { return { code: 400, message: 'Bad Request', errorCode: 'E0000001', errorSummary: `Invalid value for '${field}': ${value}`, errorLink: 'E0000001', errorId: this.generateErrorId(), }; } simulateConflictError(resource) { return { code: 409, message: 'Conflict', errorCode: 'E0000097', errorSummary: `${resource} already exists`, errorLink: 'E0000097', errorId: this.generateErrorId(), }; } generateErrorId() { const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-'; let errorId = 'oae'; for (let i = 0; i < 22; i++) { errorId += chars[Math.floor(Math.random() * chars.length)]; } return errorId; } // Format error response to match Okta's error format formatErrorResponse(scenario) { return { errorCode: scenario.errorCode, errorSummary: scenario.errorSummary, errorLink: scenario.errorLink, errorId: scenario.errorId || this.generateErrorId(), }; } } //# sourceMappingURL=error-simulator.js.map