Skip to content

Commit b5632ce

Browse files
authored
Merge pull request #624 from duffelhq/show-headers-in-reponse
feat(headers): shows http headers in client response
2 parents ad19c53 + 95ac67c commit b5632ce

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Client.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,21 @@ export interface Config {
1818
export class DuffelError extends Error {
1919
public meta: ApiResponseMeta
2020
public errors: ApiResponseError[]
21+
public headers: Record<string, string>
2122

2223
constructor({
2324
meta,
2425
errors,
26+
headers,
2527
}: {
2628
meta: ApiResponseMeta
2729
errors: ApiResponseError[]
30+
headers: Record<string, string>
2831
}) {
2932
super()
3033
this.meta = meta
3134
this.errors = errors
35+
this.headers = headers
3236
}
3337
}
3438

@@ -129,10 +133,10 @@ export class Client {
129133
}
130134

131135
if (!response.ok || ('errors' in responseBody && responseBody.errors)) {
132-
throw new DuffelError(responseBody)
136+
throw new DuffelError({ ...responseBody, headers: response.headers })
133137
}
134138

135-
return responseBody
139+
return { ...responseBody, headers: response.headers }
136140
}
137141

138142
async *paginatedRequest<T_Data = any>({

src/types/ClientType.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ export interface DuffelResponse<T_Data> {
7373
* Optional metadata for the request
7474
*/
7575
meta?: PaginationMeta
76+
77+
/**
78+
* The headers from the http response
79+
*/
80+
headers?: Record<string, string>
7681
}
7782

7883
export interface SDKOptions {

0 commit comments

Comments
 (0)