@@ -76,19 +76,28 @@ class Client {
7676 headers: {...this.headers, ...headers},
7777 method: method.name(),
7878 );
79+ try {
7980
80- if(headers['content-type'] == 'multipart/form-data') {
81- return http.request(path, data: FormData.fromMap(params), options: options);
82- }
81+ if(headers['content-type'] == 'multipart/form-data') {
82+ return http.request(path, data: FormData.fromMap(params), options: options);
83+ }
8384
84- if (method == HttpMethod.get) {
85- params.keys.forEach((key) {if (params[key] is int || params[key] is double) {
86- params[key] = params[key].toString();
87- }});
88-
89- return http.get(path, queryParameters: params, options: options);
90- } else {
91- return http.request(path, data: params, options: options);
85+ if (method == HttpMethod.get) {
86+ params.keys.forEach((key) {if (params[key] is int || params[key] is double) {
87+ params[key] = params[key].toString();
88+ }});
89+
90+ return http.get(path, queryParameters: params, options: options);
91+ } else {
92+ return http.request(path, data: params, options: options);
93+ }
94+ } on DioError catch(e) {
95+ if(e.response == null) {
96+ throw {{spec .title | caseUcfirst }}Exception(e.message);
97+ }
98+ throw {{spec .title | caseUcfirst }}Exception(e.response.data['message'],e.response.data['code'], e.response.data);
99+ } catch(e) {
100+ throw {{spec .title | caseUcfirst }}Exception(e.message);
92101 }
93102 }
94103}
0 commit comments