Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/preserve-run-key-status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@workflow/world-vercel': patch
---

Preserve upstream HTTP status codes when fetching Workflow run encryption keys.
5 changes: 4 additions & 1 deletion packages/world-vercel/src/encryption.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ describe('fetchRunKey', () => {
fetchRunKey(deploymentId, testProjectId, testRunId, {
token: 'test-token',
})
).rejects.toThrow('HTTP 404');
).rejects.toMatchObject({
message: expect.stringContaining('HTTP 404'),
status: 404,
});
});
});

Expand Down
15 changes: 13 additions & 2 deletions packages/world-vercel/src/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ import { instrumentedFetch, resolveVercelApiToken } from './http-core.js';

const KEY_BYTES = 32; // 256 bits = 32 bytes (AES-256)

class RunKeyFetchError extends Error {
readonly status: number;

constructor(message: string, status: number) {
super(message);
this.name = 'RunKeyFetchError';
this.status = status;
}
}

/**
* Derive a per-run AES-256 encryption key using HKDF-SHA256.
*
Expand Down Expand Up @@ -131,8 +141,9 @@ export async function fetchRunKey(
} catch {
body = '<unable to read response body>';
}
return new Error(
`Failed to fetch run key for ${runId} (deployment ${deploymentId}): HTTP ${res.status} ${res.statusText}${body ? ` — ${body}` : ''}`
return new RunKeyFetchError(
`Failed to fetch run key for ${runId} (deployment ${deploymentId}): HTTP ${res.status} ${res.statusText}${body ? ` — ${body}` : ''}`,
res.status
);
},
});
Expand Down
Loading