Skip to content

Commit 262e7bc

Browse files
🐛 FIX: Response headers handling (#113)
1 parent d0e3f7a commit 262e7bc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/langbase/src/common/request.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ export class Request {
6565
// All endpoints should return headers if rawResponse is true
6666
if (!isLllmGenerationEndpoint && options.body?.rawResponse) {
6767
const responseData = await response.json();
68+
// For array responses, attach rawResponse as a hidden property to preserve response type as array
69+
// while still providing access to response headers when needed
70+
if (Array.isArray(responseData)) {
71+
Object.defineProperty(responseData, 'rawResponse', {
72+
value: {
73+
headers: Object.fromEntries(response.headers.entries()),
74+
},
75+
enumerable: false,
76+
writable: true,
77+
});
78+
return responseData as T;
79+
}
6880
return {
6981
...responseData,
7082
rawResponse: {

0 commit comments

Comments
 (0)