Skip to content

Commit d3210b1

Browse files
committed
Merge branch 'master' into feat-dart-sdk-null-safety
2 parents f671804 + 1658549 commit d3210b1

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

templates/dart/lib/client.dart.twig

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,15 @@ class Client {
9696
if(e.response == null) {
9797
throw {{spec.title | caseUcfirst}}Exception(e.message);
9898
}
99-
throw {{spec.title | caseUcfirst}}Exception(e.response!.data['message'],e.response!.data['code'], e.response!.data);
99+
if(responseType == ResponseType.bytes) {
100+
if(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'], res);
103+
} else {
104+
throw {{spec.title | caseUcfirst}}Exception(e.message);
105+
}
106+
}
107+
throw {{spec.title | caseUcfirst}}Exception(e.response.data['message'],e.response.data['code'], e.response.data);
100108
} catch(e) {
101109
throw {{spec.title | caseUcfirst}}Exception(e.toString());
102110
}

templates/dart/lib/package.dart.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
library {{ language.params.packageName }};
22

33
import 'dart:io';
4+
import 'dart:convert';
45
import 'package:dio/dio.dart';
56
import 'package:meta/meta.dart';
67
import 'package:dio/adapter.dart';

templates/flutter/lib/client.dart.twig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ class Client {
127127
if(e.response == null) {
128128
throw {{spec.title | caseUcfirst}}Exception(e.message);
129129
}
130+
if(responseType == ResponseType.bytes) {
131+
if(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+
}
137+
}
130138
throw {{spec.title | caseUcfirst}}Exception(e.response.data['message'],e.response.data['code'], e.response.data);
131139
} catch(e) {
132140
throw {{spec.title | caseUcfirst}}Exception(e.message);

templates/flutter/lib/package.dart.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
library {{ language.params.packageName }};
22

33
import 'dart:io';
4+
import 'dart:convert';
45
import 'package:universal_html/html.dart' as html;
56
import 'package:dio/dio.dart';
67
import 'package:meta/meta.dart';

0 commit comments

Comments
 (0)