Skip to content

Commit 73dd3e6

Browse files
authored
Merge pull request #35 from microcmsio/fix-delete-api-response
delete apiはjsonを返さないのでそのように変更
2 parents 86fd6d6 + 3733f20 commit 73dd3e6

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/createClient.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ export const createClient = ({ serviceDomain, apiKey }: MicroCMSClient) => {
4242
/**
4343
* Make request
4444
*/
45-
const makeRequest = async <T>({
45+
const makeRequest = async ({
4646
endpoint,
4747
contentId,
4848
queries = {},
4949
method,
5050
customHeaders,
5151
customBody,
52-
}: MakeRequest): Promise<T> => {
52+
}: MakeRequest) => {
5353
const queryString = parseQuery(queries);
5454

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

72+
if (method === 'DELETE') return;
73+
7274
return response.json();
7375
} catch (error) {
7476
if (error.data) {
@@ -96,7 +98,7 @@ export const createClient = ({ serviceDomain, apiKey }: MicroCMSClient) => {
9698
if (!endpoint) {
9799
return Promise.reject(new Error('endpoint is required'));
98100
}
99-
return await makeRequest<T>({ endpoint, contentId, queries });
101+
return await makeRequest({ endpoint, contentId, queries });
100102
};
101103

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

115117
/**
@@ -123,7 +125,7 @@ export const createClient = ({ serviceDomain, apiKey }: MicroCMSClient) => {
123125
if (!endpoint) {
124126
return Promise.reject(new Error('endpoint is required'));
125127
}
126-
return await makeRequest<T & MicroCMSListContent>({
128+
return await makeRequest({
127129
endpoint,
128130
contentId,
129131
queries,
@@ -140,7 +142,7 @@ export const createClient = ({ serviceDomain, apiKey }: MicroCMSClient) => {
140142
if (!endpoint) {
141143
return Promise.reject(new Error('endpoint is required'));
142144
}
143-
return await makeRequest<T & MicroCMSObjectContent>({
145+
return await makeRequest({
144146
endpoint,
145147
queries,
146148
});

tests/write.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ describe('delete', () => {
193193
server.use(
194194
rest.delete(`${testBaseUrl}/list-type/foo`, (_, res, ctx) => {
195195
deleteApiMockFn();
196-
return res(ctx.status(202), ctx.json({}));
196+
return res(ctx.status(202));
197197
})
198198
);
199199
});

0 commit comments

Comments
 (0)