Skip to content

Commit

Permalink
fix: Return non-flattened response in case of errors, if requested
Browse files Browse the repository at this point in the history
  • Loading branch information
MattCCC committed Sep 4, 2024
1 parent 11ff763 commit c7673f5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/request-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,16 +654,16 @@ export class RequestHandler {

let data = response?.data;

// Return flattened response immediately
if (flattenResponse) {
return this.flattenData(data);
}

// Set the default response if the provided data is an empty object
if (data && typeof data === 'object' && Object.keys(data).length === 0) {
data = defaultResponse;
}

// Return flattened response immediately
if (flattenResponse) {
return this.flattenData(data);
}

const isCustomFetcher = this.isCustomFetcher();

if (isCustomFetcher) {
Expand Down
2 changes: 1 addition & 1 deletion test/request-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ describe('Request Handler', () => {

(requestHandler.requestInstance as any).request = jest
.fn()
.mockResolvedValue({});
.mockResolvedValue({ data: null });

expect(
await requestHandler.request(apiUrl, null, { method: 'head' }),
Expand Down

0 comments on commit c7673f5

Please sign in to comment.