MCPcopy Create free account
hub / github.com/freecodexyz/free-code / handleValidationError

Function handleValidationError

src/utils/model/validateModel.ts:92–146  ·  view source on GitHub ↗
(
  error: unknown,
  modelName: string,
)

Source from the content-addressed store, hash-verified

90}
91
92function handleValidationError(
93 error: unknown,
94 modelName: string,
95): { valid: boolean; error: string } {
96 // NotFoundError (404) means the model doesn't exist
97 if (error instanceof NotFoundError) {
98 const fallback = get3PFallbackSuggestion(modelName)
99 const suggestion = fallback ? `. Try '${fallback}' instead` : ''
100 return {
101 valid: false,
102 error: `Model '${modelName}' not found${suggestion}`,
103 }
104 }
105
106 // For other API errors, provide context-specific messages
107 if (error instanceof APIError) {
108 if (error instanceof AuthenticationError) {
109 return {
110 valid: false,
111 error: 'Authentication failed. Please check your API credentials.',
112 }
113 }
114
115 if (error instanceof APIConnectionError) {
116 return {
117 valid: false,
118 error: 'Network error. Please check your internet connection.',
119 }
120 }
121
122 // Check error body for model-specific errors
123 const errorBody = error.error as unknown
124 if (
125 errorBody &&
126 typeof errorBody === 'object' &&
127 'type' in errorBody &&
128 errorBody.type === 'not_found_error' &&
129 'message' in errorBody &&
130 typeof errorBody.message === 'string' &&
131 errorBody.message.includes('model:')
132 ) {
133 return { valid: false, error: `Model '${modelName}' not found` }
134 }
135
136 // Generic API error
137 return { valid: false, error: `API error: ${error.message}` }
138 }
139
140 // For unknown errors, be safe and reject
141 const errorMessage = error instanceof Error ? error.message : String(error)
142 return {
143 valid: false,
144 error: `Unable to validate model: ${errorMessage}`,
145 }
146}
147
148// @[MODEL LAUNCH]: Add a fallback suggestion chain for the new model → previous version
149/**

Callers 1

validateModelFunction · 0.85

Calls 1

get3PFallbackSuggestionFunction · 0.85

Tested by

no test coverage detected