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

Function handleValidationError

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

Source from the content-addressed store, hash-verified

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

Callers 1

validateModelFunction · 0.85

Calls 1

get3PFallbackSuggestionFunction · 0.85

Tested by

no test coverage detected