UNPKG

@aashari/mcp-server-aws-sso

Version:

Node.js/TypeScript MCP server for AWS Single Sign-On (SSO). Enables AI systems (LLMs) with tools to initiate SSO login (device auth flow), list accounts/roles, and securely execute AWS CLI commands using temporary credentials. Streamlines AI interaction w

45 lines (44 loc) 2.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleControllerError = handleControllerError; const error_util_js_1 = require("./error.util.js"); const logger_util_js_1 = require("./logger.util.js"); // Import components from modular files const error_types_util_js_1 = require("./error-types.util.js"); const error_detection_util_js_1 = require("./error-detection.util.js"); const error_formatting_util_js_1 = require("./error-formatting.util.js"); /** * Handle controller errors consistently * @param error The error to handle * @param context Context information for better error messages * @returns Never returns, always throws an error */ function handleControllerError(error, context = {}) { const methodLogger = logger_util_js_1.Logger.forContext('utils/error-handler.util.ts', 'handleControllerError'); // Extract error details const errorMessage = error instanceof Error ? error.message : String(error); const statusCode = error instanceof Error && 'statusCode' in error ? error.statusCode : undefined; // Detect error type using utility const { code, statusCode: detectedStatus } = (0, error_detection_util_js_1.detectErrorType)(error, context); // Combine detected status with explicit status const finalStatusCode = statusCode || detectedStatus; // Format entity information for logging const { entityType, entityId, operation } = context; const entity = entityType || 'resource'; const entityIdStr = entityId ? typeof entityId === 'string' ? entityId : JSON.stringify(entityId) : ''; const actionStr = operation || 'processing'; // Log detailed error information methodLogger.error(`Error ${actionStr} ${entity}${entityIdStr ? `: ${entityIdStr}` : ''}: ${errorMessage}`, error); // Create user-friendly error message for the response const message = code === error_types_util_js_1.ErrorCode.VALIDATION_ERROR ? errorMessage : (0, error_formatting_util_js_1.createUserFriendlyErrorMessage)(code, context, errorMessage); // Throw an appropriate API error with the user-friendly message throw (0, error_util_js_1.createApiError)(message, finalStatusCode, error); }