Skip to content

Commit 3f7b07b

Browse files
committed
fix: ensure consistent error message format in handleOpenAIError
- Wrap all non-ByteString errors with provider-specific prefix - Handle potential undefined error messages safely - Maintain consistent error format expected by unit tests
1 parent fc6e9c6 commit 3f7b07b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/api/providers/utils/openai-error-handler.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ import i18n from "../../../i18n/setup"
1313
*/
1414
export function handleOpenAIError(error: unknown, providerName: string): Error {
1515
if (error instanceof Error) {
16+
const msg = error.message || ""
17+
1618
// Invalid character/ByteString conversion error in API key
17-
if (error.message.includes("Cannot convert argument to a ByteString")) {
19+
if (msg.includes("Cannot convert argument to a ByteString")) {
1820
return new Error(i18n.t("common:errors.api.invalidKeyInvalidChars"))
1921
}
2022

21-
// Add more error message transformations here as needed
22-
23-
// Return original error if no transformation matches
24-
return error
23+
// For other Error instances, wrap with provider-specific prefix
24+
return new Error(`${providerName} completion error: ${msg}`)
2525
}
2626

27-
// If it's not even an Error object, wrap it
28-
return new Error(`${providerName} error: ${String(error)}`)
27+
// Non-Error: wrap with provider-specific prefix
28+
return new Error(`${providerName} completion error: ${String(error)}`)
2929
}

0 commit comments

Comments
 (0)