-
Notifications
You must be signed in to change notification settings - Fork 4.2k
fix(gateway): remove cause from custom handling of GatewayAuthenticationError error
#11111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,14 @@ | ||
| import { | ||
| GatewayAuthenticationError, | ||
| GatewayModelNotFoundError, | ||
| GatewayAuthenticationError | ||
| } from '@ai-sdk/gateway'; | ||
| import { AISDKError } from '@ai-sdk/provider'; | ||
|
|
||
| export function wrapGatewayError(error: unknown): unknown { | ||
| if ( | ||
| GatewayAuthenticationError.isInstance(error) || | ||
| GatewayModelNotFoundError.isInstance(error) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The View Details📝 Patch Detailsdiff --git a/packages/ai/src/prompt/wrap-gateway-error.ts b/packages/ai/src/prompt/wrap-gateway-error.ts
index 0417be108..4bb058e1e 100644
--- a/packages/ai/src/prompt/wrap-gateway-error.ts
+++ b/packages/ai/src/prompt/wrap-gateway-error.ts
@@ -7,6 +7,7 @@ export function wrapGatewayError(error: unknown): unknown {
name: 'GatewayError',
message:
'Unauthenticated. Configure AI_GATEWAY_API_KEY or configure and use a provider module. Learn more: https://vercel.link/unauthenticated-ai-gateway-v6',
+ cause: error,
});
}
AnalysisMissing cause property breaks error chain in wrapGatewayError()What fails: How to reproduce: import { wrapGatewayError } from './packages/ai/src/prompt/wrap-gateway-error';
import { GatewayAuthenticationError } from '@ai-sdk/gateway';
const originalError = new GatewayAuthenticationError({
message: 'Auth failed',
statusCode: 401,
cause: new Error('Network timeout')
});
const wrappedError = wrapGatewayError(originalError) as AISDKError;
console.log(wrappedError.cause); // undefined - original error is lostResult: The Expected: The Reference: AISDKError constructor accepts |
||
| ) { | ||
| if (GatewayAuthenticationError.isInstance(error)) { | ||
| return new AISDKError({ | ||
| name: 'GatewayError', | ||
| message: | ||
| 'Unauthenticated. Configure AI_GATEWAY_API_KEY or configure and use a provider module. Learn more: https://vercel.link/unauthenticated-ai-gateway-v6', | ||
| cause: error, | ||
| }); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lars @mclenhard throwing the custom
unauthenticatederror forGatewayModelNotFoundErrorwas incorrect. Do we want a custom error for when a model was not found? I don't think we need it?