File tree 3 files changed +31
-5
lines changed
3 files changed +31
-5
lines changed Original file line number Diff line number Diff line change @@ -126,7 +126,7 @@ export function generateSearchQueries({
126
126
system : systemPrompt ( ) ,
127
127
prompt,
128
128
onError ( { error } ) {
129
- throw error
129
+ throwAiError ( 'generateSearchQueries' , error )
130
130
} ,
131
131
} )
132
132
}
@@ -174,7 +174,7 @@ function processSearchResult({
174
174
system : systemPrompt ( ) ,
175
175
prompt,
176
176
onError ( { error } ) {
177
- throw error
177
+ throwAiError ( 'processSearchResult' , error )
178
178
} ,
179
179
} )
180
180
}
@@ -204,7 +204,7 @@ export function writeFinalReport({
204
204
system : systemPrompt ( ) ,
205
205
prompt : _prompt ,
206
206
onError ( { error } ) {
207
- throw error
207
+ throwAiError ( 'writeFinalReport' , error )
208
208
} ,
209
209
} )
210
210
}
Original file line number Diff line number Diff line change @@ -37,8 +37,7 @@ export function generateFeedback({
37
37
system : systemPrompt ( ) ,
38
38
prompt,
39
39
onError ( { error } ) {
40
- console . error ( `generateFeedback` , error )
41
- throw error
40
+ throwAiError ( 'generateFeedback' , error )
42
41
} ,
43
42
} )
44
43
Original file line number Diff line number Diff line change
1
+ import { APICallError } from 'ai'
2
+
3
+ /**
4
+ * Parse an error thrown by the AI SDK, and re-throw it with a human-readable message
5
+ */
6
+ export function throwAiError ( operation : string , error : unknown ) {
7
+ if ( APICallError . isInstance ( error ) ) {
8
+ let message = error . message
9
+ if ( error . statusCode ) message += ` (${ error . statusCode } )`
10
+ if ( error . cause ) message += `\nCause: ${ error . cause } `
11
+ if ( error . responseBody ) message += `\nResponse: ${ error . responseBody } `
12
+ if ( error . url ) message += `\nURL: ${ error . url } `
13
+
14
+ console . error ( `[${ operation } ]` , error , {
15
+ statusCode : error . statusCode ,
16
+ response : error . responseBody ,
17
+ cause : error . cause ,
18
+ stack : error . stack ,
19
+ isRetryable : error . isRetryable ,
20
+ url : error . url ,
21
+ } )
22
+ throw new Error ( message )
23
+ } else {
24
+ console . error ( `[${ operation } ]` , error )
25
+ }
26
+ throw error
27
+ }
You can’t perform that action at this time.
0 commit comments