Skip to content

Commit 832b645

Browse files
authored
fix(core/client): wrong content-type detection. (#159)
Closes #158
1 parent 8a8b606 commit 832b645

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

.changeset/hip-peaches-sell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@ts-rest/core': patch
3+
---
4+
5+
fix(core): wrong "content-type" detection

libs/ts-rest/core/src/lib/client.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,20 @@ export const defaultApi: ApiFetcher = async ({
107107
}) => {
108108
const result = await fetch(path, { method, headers, body, credentials });
109109
const contentType = result.headers.get('content-type');
110+
110111
if (!contentType) {
111112
throw TypeError('Resource Response missing content-type header');
112113
}
113-
switch (contentType) {
114-
case 'application/json': {
115-
return { status: result.status, body: await result.json() };
116-
}
117-
case 'text/plain': {
118-
return { status: result.status, body: await result.text() };
119-
}
120-
default: {
121-
return { status: result.status, body: await result.blob() };
122-
}
114+
115+
if (contentType.includes('application/json')) {
116+
return { status: result.status, body: await result.json() };
117+
}
118+
119+
if (contentType.includes('text/plain')) {
120+
return { status: result.status, body: await result.text() };
123121
}
122+
123+
return { status: result.status, body: await result.blob() };
124124
};
125125

126126
const createFormData = (body: unknown) => {

0 commit comments

Comments
 (0)