@simonecoelhosfo/optimizely-mcp-server
Version:
Optimizely MCP Server for AI assistants with integrated CLI tools
84 lines • 3.19 kB
JavaScript
/**
* Hard Stop Error Class
* @description Represents unrecoverable errors that require user intervention
*
* Used for scenarios where the system cannot proceed without explicit user input:
* - Entity already exists (duplicate keys)
* - Required references not found
* - Foreign key constraint violations
* - Critical validation failures
*
* @author Optimizely MCP Server
* @version 1.0.0
*/
export class HardStopError extends Error {
code;
reason;
nextAction;
httpStatus;
forbiddenActions;
fatal = true;
constructor(code, reason, message, nextAction = "ASK_USER", httpStatus = 409, forbiddenActions = ["retry", "continue", "auto_fix"]) {
super(message);
this.code = code;
this.reason = reason;
this.nextAction = nextAction;
this.httpStatus = httpStatus;
this.forbiddenActions = forbiddenActions;
this.name = 'HardStopError';
// Ensure proper prototype chain for instanceof checks
Object.setPrototypeOf(this, HardStopError.prototype);
}
/**
* Convert to response format
*/
toResponse() {
return {
status: "HARD_STOP_REQUIRED",
error: {
code: this.httpStatus,
type: this.code,
message: this.message,
reason: this.reason,
fatal: this.fatal
},
required_action: {
type: this.nextAction,
message: "Manual intervention required. Ask user how to proceed.",
forbidden_actions: this.forbiddenActions
},
immediate_guidance: {
critical_rule: "STOP all operations. Do not attempt workarounds.",
detected_issue: `${this.reason} - unrecoverable without user input`,
next_step: "Present error to user and await instructions"
},
ai_instructions: {
critical: "DO NOT RETRY. DO NOT ATTEMPT FIXES. ASK USER FOR HELP.",
display_to_user: `Error: ${this.message}\n\nThis requires your input to proceed.`,
retry_will_fail: true
}
};
}
}
/**
* Common hard stop error types
*/
export const HardStopErrorType = {
ENTITY_ALREADY_EXISTS: "ENTITY_ALREADY_EXISTS",
FOREIGN_KEY_CONSTRAINT: "FOREIGN_KEY_CONSTRAINT",
REQUIRED_REFERENCE_MISSING: "REQUIRED_REFERENCE_MISSING",
DATABASE_CONSTRAINT_VIOLATION: "DATABASE_CONSTRAINT_VIOLATION",
QUOTA_EXCEEDED: "QUOTA_EXCEEDED",
INVALID_PROJECT_STATE: "INVALID_PROJECT_STATE",
PLATFORM_ARCHITECTURE_MISMATCH: "PLATFORM_ARCHITECTURE_MISMATCH",
ZOD_VALIDATION_ERROR: "ZOD_VALIDATION_ERROR",
ENTITY_TYPE_MISMATCH: "ENTITY_TYPE_MISMATCH",
DATABASE_SCHEMA_ERROR: "DATABASE_SCHEMA_ERROR",
PROJECT_TYPE_AMBIGUOUS: "PROJECT_TYPE_AMBIGUOUS",
INVALID_PLATFORM_VALUE: "INVALID_PLATFORM_VALUE",
INVALID_ENUM_VALUE: "INVALID_ENUM_VALUE",
PAGINATION_BYPASS_LIMIT_EXCEEDED: "PAGINATION_BYPASS_LIMIT_EXCEEDED",
CONSENT_REQUIRED: "CONSENT_REQUIRED",
OPERATION_NOT_SUPPORTED: "OPERATION_NOT_SUPPORTED"
};
//# sourceMappingURL=HardStopError.js.map