Skip to content

Commit

Permalink
Merge pull request #35 from microcmsio/fix-delete-api-response
Browse files Browse the repository at this point in the history
delete apiはjsonを返さないのでそのように変更
  • Loading branch information
dc7290 authored Aug 9, 2022
2 parents 86fd6d6 + 3733f20 commit 73dd3e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/createClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ export const createClient = ({ serviceDomain, apiKey }: MicroCMSClient) => {
/**
* Make request
*/
const makeRequest = async <T>({
const makeRequest = async ({
endpoint,
contentId,
queries = {},
method,
customHeaders,
customBody,
}: MakeRequest): Promise<T> => {
}: MakeRequest) => {
const queryString = parseQuery(queries);

const baseHeaders: RequestInit = {
Expand All @@ -69,6 +69,8 @@ export const createClient = ({ serviceDomain, apiKey }: MicroCMSClient) => {
throw new Error(`fetch API response status: ${response.status}`);
}

if (method === 'DELETE') return;

return response.json();
} catch (error) {
if (error.data) {
Expand Down Expand Up @@ -96,7 +98,7 @@ export const createClient = ({ serviceDomain, apiKey }: MicroCMSClient) => {
if (!endpoint) {
return Promise.reject(new Error('endpoint is required'));
}
return await makeRequest<T>({ endpoint, contentId, queries });
return await makeRequest({ endpoint, contentId, queries });
};

/**
Expand All @@ -109,7 +111,7 @@ export const createClient = ({ serviceDomain, apiKey }: MicroCMSClient) => {
if (!endpoint) {
return Promise.reject(new Error('endpoint is required'));
}
return await makeRequest<MicroCMSListResponse<T>>({ endpoint, queries });
return await makeRequest({ endpoint, queries });
};

/**
Expand All @@ -123,7 +125,7 @@ export const createClient = ({ serviceDomain, apiKey }: MicroCMSClient) => {
if (!endpoint) {
return Promise.reject(new Error('endpoint is required'));
}
return await makeRequest<T & MicroCMSListContent>({
return await makeRequest({
endpoint,
contentId,
queries,
Expand All @@ -140,7 +142,7 @@ export const createClient = ({ serviceDomain, apiKey }: MicroCMSClient) => {
if (!endpoint) {
return Promise.reject(new Error('endpoint is required'));
}
return await makeRequest<T & MicroCMSObjectContent>({
return await makeRequest({
endpoint,
queries,
});
Expand Down
2 changes: 1 addition & 1 deletion tests/write.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ describe('delete', () => {
server.use(
rest.delete(`${testBaseUrl}/list-type/foo`, (_, res, ctx) => {
deleteApiMockFn();
return res(ctx.status(202), ctx.json({}));
return res(ctx.status(202));
})
);
});
Expand Down

0 comments on commit 73dd3e6

Please sign in to comment.