Skip to content

Commit 9a099aa

Browse files
committed
check content type
1 parent c1279cb commit 9a099aa

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

templates/dart/lib/client.dart.twig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,12 @@ class Client {
9797
throw {{spec.title | caseUcfirst}}Exception(e.message);
9898
}
9999
if(responseType == ResponseType.bytes) {
100-
final res = json.decode(utf8.decode(e.response.data));
101-
throw {{spec.title | caseUcfirst}}Exception(res['message'],res['code'], res);
100+
fif(e.response.headers['content-type'].contains('application/json')) {
101+
final res = json.decode(utf8.decode(e.response.data));
102+
throw {{spec.title | caseUcfirst}}Exception(res['message'],res['code'], e.response);
103+
} else {
104+
throw {{spec.title | caseUcfirst}}Exception(e.message);
105+
}
102106
}
103107
throw {{spec.title | caseUcfirst}}Exception(e.response.data['message'],e.response.data['code'], e.response.data);
104108
} catch(e) {

templates/flutter/lib/client.dart.twig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,12 @@ class Client {
128128
throw {{spec.title | caseUcfirst}}Exception(e.message);
129129
}
130130
if(responseType == ResponseType.bytes) {
131-
final res = json.decode(utf8.decode(e.response.data));
132-
throw {{spec.title | caseUcfirst}}Exception(res['message'],res['code'], res);
131+
fif(e.response.headers['content-type'].contains('application/json')) {
132+
final res = json.decode(utf8.decode(e.response.data));
133+
throw {{spec.title | caseUcfirst}}Exception(res['message'],res['code'], e.response);
134+
} else {
135+
throw {{spec.title | caseUcfirst}}Exception(e.message);
136+
}
133137
}
134138
throw {{spec.title | caseUcfirst}}Exception(e.response.data['message'],e.response.data['code'], e.response.data);
135139
} catch(e) {

0 commit comments

Comments
 (0)