@@ -2,7 +2,7 @@ import os from 'node:os';
22import { getVercelOidcToken } from '@vercel/oidc' ;
33import { WorkflowAPIError } from '@workflow/errors' ;
44import { type StructuredError , StructuredErrorSchema } from '@workflow/world' ;
5- import { ZodError , type z } from 'zod' ;
5+ import type { z } from 'zod' ;
66import { version } from './version.js' ;
77
88export interface APIConfig {
@@ -174,10 +174,11 @@ export async function makeRequest<T>({
174174 headers . set ( 'X-Request-Time' , Date . now ( ) . toString ( ) ) ;
175175
176176 const url = `${ baseUrl } ${ endpoint } ` ;
177- const response = await fetch ( url , {
177+ const request = new Request ( url , {
178178 ...options ,
179179 headers,
180- } as RequestInit ) ;
180+ } ) ;
181+ const response = await fetch ( request ) ;
181182
182183 if ( ! response . ok ) {
183184 const errorData = ( await response . json ( ) . catch ( ( ) => ( { } ) ) ) as any ;
@@ -186,28 +187,23 @@ export async function makeRequest<T>({
186187 . map ( ( [ key , value ] : [ string , string ] ) => `-H "${ key } : ${ value } "` )
187188 . join ( ' ' ) ;
188189 console . error (
189- `Failed to fetch, reproduce with:\ncurl -X ${ options . method } ${ stringifiedHeaders } "${ url } "`
190+ `Failed to fetch, reproduce with:\ncurl -X ${ request . method } ${ stringifiedHeaders } "${ url } "`
190191 ) ;
191192 }
192193 throw new WorkflowAPIError (
193194 errorData . message ||
194- `${ options . method ?? 'GET' } ${ endpoint } -> HTTP ${ response . status } : ${ response . statusText } ` ,
195+ `${ request . method } ${ endpoint } -> HTTP ${ response . status } : ${ response . statusText } ` ,
195196 { url, status : response . status , code : errorData . code }
196197 ) ;
197198 }
198199
200+ const text = await response . text ( ) ;
201+
199202 try {
200- const text = await response . text ( ) ;
201203 return schema . parse ( JSON . parse ( text ) ) ;
202204 } catch ( error ) {
203- if ( error instanceof ZodError ) {
204- throw new WorkflowAPIError (
205- `Failed to parse server response for ${ options . method ?? 'GET' } ${ endpoint } : ${ error . message } ` ,
206- { url, cause : error }
207- ) ;
208- }
209205 throw new WorkflowAPIError (
210- `Failed to parse server response for ${ options . method ?? 'GET' } ${ endpoint } ` ,
206+ `Failed to parse server response for ${ request . method } ${ endpoint } :\n\n ${ error } \n\nResponse body: ${ text } ` ,
211207 { url, cause : error }
212208 ) ;
213209 }
0 commit comments