Skip to content

Commit 1ec4519

Browse files
committed
chore: fixed response types across sdks
1 parent 2d02e13 commit 1ec4519

File tree

13 files changed

+35
-21
lines changed

13 files changed

+35
-21
lines changed

templates/apple/Sources/Client.swift.twig

+2-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ open class Client {
346346
throw {{ spec.title | caseUcfirst }}Error(
347347
message: message,
348348
code: Int(response.status.code),
349-
type: type
349+
type: type,
350+
data
350351
)
351352
}
352353
}

templates/cli/lib/client.js.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class Client {
158158
globalConfig.setCurrentSession('');
159159
globalConfig.removeSession(current);
160160
}
161-
throw new {{spec.title | caseUcfirst}}Exception(json.message, json.code, json.type, json);
161+
throw new {{spec.title | caseUcfirst}}Exception(json.message, json.code, json.type, text);
162162
}
163163

164164
if (responseType === "arraybuffer") {

templates/dart/lib/src/client_mixin.dart.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class ClientMixin {
8181
response['message'],
8282
response['code'],
8383
response['type'],
84-
response,
84+
res.body,
8585
);
8686
} else {
8787
throw {{spec.title | caseUcfirst}}Exception(res.body);

templates/deno/src/client.ts.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class Client {
113113
} catch (error) {
114114
throw new {{spec.title | caseUcfirst}}Exception(text, response.status, "", text);
115115
}
116-
throw new {{spec.title | caseUcfirst}}Exception(json.message, json.code, json.type, json);
116+
throw new {{spec.title | caseUcfirst}}Exception(json.message, json.code, json.type, text);
117117
}
118118

119119
if (responseType === "arraybuffer") {

templates/dotnet/Package/Client.cs.twig

+11-5
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ namespace {{ spec.title | caseUcfirst }}
230230
var code = (int)response.StatusCode;
231231

232232
if (code >= 400) {
233-
var message = await response.Content.ReadAsStringAsync();
233+
var text = await response.Content.ReadAsStringAsync();
234+
var message = "";
235+
var type = "";
234236

235237
string contentType = string.Empty;
236238
if (response.Content.Headers.TryGetValues("Content-Type", out var contentTypes))
@@ -239,10 +241,11 @@ namespace {{ spec.title | caseUcfirst }}
239241
}
240242

241243
if (contentType.Contains("application/json")) {
242-
message = JObject.Parse(message)["message"]!.ToString();
244+
message = JObject.Parse(text)["message"]!.ToString();
245+
type = JObject.Parse(text)["type"]!.ToString();
243246
}
244247

245-
throw new {{spec.title | caseUcfirst}}Exception(message, code);
248+
throw new {{spec.title | caseUcfirst}}Exception(message, code, type, text);
246249
}
247250

248251
return response.Headers.Location.OriginalString;
@@ -286,13 +289,16 @@ namespace {{ spec.title | caseUcfirst }}
286289
var isJson = contentType.Contains("application/json");
287290

288291
if (code >= 400) {
289-
var message = await response.Content.ReadAsStringAsync();
292+
var text = await response.Content.ReadAsStringAsync();
293+
var message = "";
294+
var type = "";
290295

291296
if (isJson) {
292297
message = JObject.Parse(message)["message"]!.ToString();
298+
type = JObject.Parse(message)["type"]!.ToString();
293299
}
294300

295-
throw new {{spec.title | caseUcfirst}}Exception(message, code);
301+
throw new {{spec.title | caseUcfirst}}Exception(message, code, type, text);
296302
}
297303

298304
if (isJson)

templates/flutter/lib/src/client_mixin.dart.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class ClientMixin {
8181
response['message'],
8282
response['code'],
8383
response['type'],
84-
response,
84+
res.body,
8585
);
8686
} else {
8787
throw {{spec.title | caseUcfirst}}Exception(res.body);

templates/node/src/client.ts.twig

+3-2
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ class Client {
265265
let data: any = null;
266266

267267
const response = await fetch(uri, options);
268+
const text = await response.text();
268269

269270
const warnings = response.headers.get('x-{{ spec.title | lower }}-warning');
270271
if (warnings) {
@@ -277,12 +278,12 @@ class Client {
277278
data = await response.arrayBuffer();
278279
} else {
279280
data = {
280-
message: await response.text()
281+
message: text
281282
};
282283
}
283284

284285
if (400 <= response.status) {
285-
throw new {{spec.title | caseUcfirst}}Exception(data?.message, response.status, data?.type, data);
286+
throw new {{spec.title | caseUcfirst}}Exception(data?.message, response.status, data?.type, text);
286287
}
287288

288289
return data;

templates/python/package/client.py.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class Client:
109109
if response != None:
110110
content_type = response.headers['Content-Type']
111111
if content_type.startswith('application/json'):
112-
raise {{spec.title | caseUcfirst}}Exception(response.json()['message'], response.status_code, response.json().get('type'), response.json())
112+
raise {{spec.title | caseUcfirst}}Exception(response.json()['message'], response.status_code, response.json().get('type'), response.text)
113113
else:
114114
raise {{spec.title | caseUcfirst}}Exception(response.text, response.status_code)
115115
else:

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ class Client {
415415
try {
416416
let data = null;
417417
const response = await fetch(url.toString(), options);
418+
const text = await response.text()
418419

419420
const warnings = response.headers.get('x-{{ spec.title | lower }}-warning');
420421
if (warnings) {
@@ -425,12 +426,12 @@ class Client {
425426
data = await response.json();
426427
} else {
427428
data = {
428-
message: await response.text()
429+
message: text
429430
};
430431
}
431432

432433
if (400 <= response.status) {
433-
throw new {{spec.title | caseUcfirst}}Exception(data?.message, response.status, data?.type, data);
434+
throw new {{spec.title | caseUcfirst}}Exception(data?.message, response.status, data?.type, text);
434435
}
435436

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

templates/ruby/lib/container/client.rb.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ module {{ spec.title | caseUcfirst }}
252252
end
253253

254254
if response.code.to_i >= 400
255-
raise {{spec.title | caseUcfirst}}::Exception.new(result['message'], result['status'], result['type'], result)
255+
raise {{spec.title | caseUcfirst}}::Exception.new(result['message'], result['status'], result['type'], response)
256256
end
257257

258258
unless response_type.respond_to?("from")

templates/swift/Sources/Client.swift.twig

+4-2
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ open class Client {
285285
throw {{ spec.title | caseUcfirst }}Error(
286286
message: message,
287287
code: Int(response.status.code),
288-
type: type
288+
type: type,
289+
data
289290
)
290291
}
291292

@@ -382,7 +383,8 @@ open class Client {
382383
throw {{ spec.title | caseUcfirst }}Error(
383384
message: message,
384385
code: Int(response.status.code),
385-
type: type
386+
type: type,
387+
data
386388
)
387389
}
388390
}

templates/swift/Sources/Models/Error.swift.twig

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ open class {{ spec.title | caseUcfirst}}Error : Swift.Error, Decodable {
55
public let message: String
66
public let code: Int?
77
public let type: String?
8+
public let response: String?
89

9-
init(message: String, code: Int? = nil, type: String? = nil) {
10+
init(message: String, code: Int? = nil, type: String? = nil, response: String? = nil) {
1011
self.message = message
1112
self.code = code
1213
self.type = type
14+
self.response = response
1315
}
1416
}
1517

templates/web/src/client.ts.twig

+3-2
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ class Client {
671671
let data: any = null;
672672

673673
const response = await fetch(uri, options);
674+
const text = await response.text();
674675

675676
const warnings = response.headers.get('x-{{ spec.title | lower }}-warning');
676677
if (warnings) {
@@ -683,12 +684,12 @@ class Client {
683684
data = await response.arrayBuffer();
684685
} else {
685686
data = {
686-
message: await response.text()
687+
message: text
687688
};
688689
}
689690

690691
if (400 <= response.status) {
691-
throw new {{spec.title | caseUcfirst}}Exception(data?.message, response.status, data?.type, data);
692+
throw new {{spec.title | caseUcfirst}}Exception(data?.message, response.status, data?.type, text);
692693
}
693694

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

0 commit comments

Comments
 (0)