Skip to content

Commit 0e72ba9

Browse files
committed
fix: structure
1 parent 771cf9b commit 0e72ba9

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

templates/node/src/client.ts.twig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,13 @@ class Client {
282282
}
283283

284284
if (400 <= response.status) {
285-
throw new {{spec.title | caseUcfirst}}Exception(data?.message, response.status, data?.type, JSON.stringify(data));
285+
let responseText = '';
286+
if (response.headers.get('content-type')?.includes('application/json') || responseType === 'arrayBuffer') {
287+
responseText = JSON.stringify(data);
288+
} else {
289+
responseText = data?.message;
290+
}
291+
throw new {{spec.title | caseUcfirst}}Exception(data?.message, response.status, data?.type, responseText);
286292
}
287293

288294
return data;

templates/react-native/src/client.ts.twig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,13 @@ class Client {
431431
}
432432

433433
if (400 <= response.status) {
434-
throw new {{spec.title | caseUcfirst}}Exception(data?.message, response.status, data?.type, JSON.stringify(data));
434+
let responseText = '';
435+
if (response.headers.get('content-type')?.includes('application/json') || responseType === 'arrayBuffer') {
436+
responseText = JSON.stringify(data);
437+
} else {
438+
responseText = data?.message;
439+
}
440+
throw new {{spec.title | caseUcfirst}}Exception(data?.message, response.status, data?.type, responseText);
435441
}
436442

437443
const cookieFallback = response.headers.get('X-Fallback-Cookies');

templates/web/src/client.ts.twig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,13 @@ class Client {
688688
}
689689

690690
if (400 <= response.status) {
691-
throw new {{spec.title | caseUcfirst}}Exception(data?.message, response.status, data?.type, JSON.stringify(data));
691+
let responseText = '';
692+
if (response.headers.get('content-type')?.includes('application/json') || responseType === 'arrayBuffer') {
693+
responseText = JSON.stringify(data);
694+
} else {
695+
responseText = data?.message;
696+
}
697+
throw new {{spec.title | caseUcfirst}}Exception(data?.message, response.status, data?.type, responseText);
692698
}
693699

694700
const cookieFallback = response.headers.get('X-Fallback-Cookies');

0 commit comments

Comments
 (0)