@@ -108,18 +108,27 @@ class Client {
108108 method: method.name(),
109109 );
110110
111- if(headers['content-type'] == 'multipart/form-data') {
112- return http.request(path, data: FormData.fromMap(params), options: options);
113- }
111+ try {
112+ if(headers['content-type'] == 'multipart/form-data') {
113+ return await http.request(path, data: FormData.fromMap(params), options: options);
114+ }
114115
115- if (method == HttpMethod.get) {
116- params.keys.forEach((key) {if (params[key] is int || params[key] is double) {
117- params[key] = params[key].toString();
118- }});
119-
120- return http.get(path, queryParameters: params, options: options);
121- } else {
122- return http.request(path, data: params, options: options);
116+ if (method == HttpMethod.get) {
117+ params.keys.forEach((key) {if (params[key] is int || params[key] is double) {
118+ params[key] = params[key].toString();
119+ }});
120+
121+ return await http.get(path, queryParameters: params, options: options);
122+ } else {
123+ return await http.request(path, data: params, options: options);
124+ }
125+ } on DioError catch(e) {
126+ if(e.response == null) {
127+ throw {{spec .title | caseUcfirst }}Exception(e.message);
128+ }
129+ throw {{spec .title | caseUcfirst }}Exception(e.response.data['message'],e.response.data['code'], e.response.data);
130+ } catch(e) {
131+ throw {{spec .title | caseUcfirst }}Exception(e.message);
123132 }
124133 }
125134}
0 commit comments