Skip to content

Commit 3fa8679

Browse files
authored
fix: do not throw error for missing content-type header (#167)
1 parent 8debc53 commit 3fa8679

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

.changeset/nine-wasps-flash.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+
Do not throw error for missing content-type header

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,11 @@ export const defaultApi: ApiFetcher = async ({
108108
const result = await fetch(path, { method, headers, body, credentials });
109109
const contentType = result.headers.get('content-type');
110110

111-
if (!contentType) {
112-
throw TypeError('Resource Response missing content-type header');
113-
}
114-
115-
if (contentType.includes('application/json')) {
111+
if (contentType?.includes('application/json')) {
116112
return { status: result.status, body: await result.json() };
117113
}
118114

119-
if (contentType.includes('text/plain')) {
115+
if (contentType?.includes('text/plain')) {
120116
return { status: result.status, body: await result.text() };
121117
}
122118

libs/ts-rest/express/src/lib/ts-rest-express.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ const transformAppRouteMutationImplementation = (
243243

244244
return res.status(statusCode).json(result.body);
245245
} catch (e) {
246-
return next?.(e);
246+
return next(e);
247247
}
248248
};
249249

0 commit comments

Comments
 (0)