export type TSmartAiProviderErrorCode = | 'ABORTED' | 'CLOSED' | 'CREDENTIAL_INVALID' | 'INVALID_ARGUMENT' | 'LOGIN_BUSY' | 'LOGIN_CANCELED' | 'LOGIN_FAILED' | 'MODEL_LIST_FAILED' | 'NETWORK_FAILED' | 'PROTOCOL_ERROR' | 'REFRESH_FAILED' | 'TIMEOUT'; const codes = new Set([ 'ABORTED', 'CLOSED', 'CREDENTIAL_INVALID', 'INVALID_ARGUMENT', 'LOGIN_BUSY', 'LOGIN_CANCELED', 'LOGIN_FAILED', 'MODEL_LIST_FAILED', 'NETWORK_FAILED', 'PROTOCOL_ERROR', 'REFRESH_FAILED', 'TIMEOUT', ]); export class SmartAiProviderError extends Error { public readonly code: TSmartAiProviderErrorCode; constructor(codeArg: TSmartAiProviderErrorCode) { const code = codes.has(codeArg) ? codeArg : 'PROTOCOL_ERROR'; super(`SmartAI provider operation failed (${code}).`); this.name = 'SmartAiProviderError'; this.code = code; Object.setPrototypeOf(this, new.target.prototype); this.stack = `${this.name}: ${this.message}`; } public toJSON(): { name: string; code: TSmartAiProviderErrorCode; message: string } { return { name: this.name, code: this.code, message: this.message }; } } export const createSmartAiProviderError = ( codeArg: TSmartAiProviderErrorCode, ): SmartAiProviderError => new SmartAiProviderError(codeArg);