Skip to content

Commit 7b03fcd

Browse files
committed
refactor(client-fetch): improves client-fetch types to allow usage of ts-reset
1 parent 7df6059 commit 7b03fcd

File tree

2 files changed

+8
-4
lines changed
  • packages/openapi-ts/src/plugins/@hey-api

2 files changed

+8
-4
lines changed

packages/openapi-ts/src/plugins/@hey-api/client-fetch/bundle/client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,16 @@ export const createClient = (config: Config = {}): Client => {
143143
};
144144
}
145145

146-
let error = await response.text();
146+
const textError = await response.text();
147+
let jsonError: unknown;
147148

148149
try {
149-
error = JSON.parse(error);
150+
jsonError = JSON.parse(textError);
150151
} catch {
151152
// noop
152153
}
153154

155+
const error = jsonError ?? textError;
154156
let finalError = error;
155157

156158
for (const fn of interceptors.error._fns) {

packages/openapi-ts/src/plugins/@hey-api/client-next/bundle/client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,16 @@ export const createClient = (config: Config = {}): Client => {
128128
};
129129
}
130130

131-
let error = await response.text();
131+
const textError = await response.text();
132+
let jsonError: unknown;
132133

133134
try {
134-
error = JSON.parse(error);
135+
jsonError = JSON.parse(textError);
135136
} catch {
136137
// noop
137138
}
138139

140+
const error = jsonError ?? textError;
139141
let finalError = error;
140142

141143
for (const fn of interceptors.error._fns) {

0 commit comments

Comments
 (0)