Skip to content

Commit 6cd1a47

Browse files
authored
Additional error debugging when failing to validate server response (#647)
1 parent f396833 commit 6cd1a47

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

.changeset/whole-lights-camp.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@workflow/world-vercel": patch
3+
---
4+
5+
Additional error debugging when failing to validate server response

packages/world-vercel/src/utils.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import os from 'node:os';
22
import { getVercelOidcToken } from '@vercel/oidc';
33
import { WorkflowAPIError } from '@workflow/errors';
44
import { type StructuredError, StructuredErrorSchema } from '@workflow/world';
5-
import { ZodError, type z } from 'zod';
5+
import type { z } from 'zod';
66
import { version } from './version.js';
77

88
export 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

Comments
 (0)