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
71 changes: 0 additions & 71 deletions src/apiReport.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/apiWithLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import chalk from 'chalk';
import { cloneResponse } from './cloneResponse.ts';
import { timeSpan } from './timeSpan.ts';
import { apiDebug }from './apiDebug.ts';
import { apiReport } from './apiReport.ts';
import { getRequestMock, saveRequestMock } from './apiCache.ts';
import {createResponse} from './createResponse.ts';
import {getCurl} from './getCurl.ts';
Expand Down Expand Up @@ -69,15 +68,6 @@ export const apiWithLog = async (
response,
});

await apiReport({
init,
options,
getBody,
response,
json,
text,
});

const { responseCopy } = await cloneResponse(response, text);

return responseCopy;
Expand Down
4 changes: 3 additions & 1 deletion src/cloneResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export const cloneResponse = async (
// @ts-ignore
const ResponseConstructor = fetch.Response || global.Response || response.constructor;

const responseCopy = new ResponseConstructor(text, {
const body = response.status === 204 ? null : text;

const responseCopy = new ResponseConstructor(body, {
status: response.status,
statusText: response.statusText,
headers: response.headers,
Expand Down
16 changes: 14 additions & 2 deletions src/createResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,22 @@ export const createResponse = async (
url: options.url,
};

const responseBody = body ?? responseOptions;
const getResponseBody = () => {
if (options?.status === 204) {
return null;
}

if (body) {
return JSON.stringify(body);
}

return JSON.stringify(responseOptions);
}

const responseBody = getResponseBody();

try {
return new Response(JSON.stringify(responseBody), responseOptions);
return new Response(responseBody, responseOptions);
} catch (error) {
return responseOptions;
}
Expand Down