1
- import 'dart:io' ;
2
- import 'package:dio/dio.dart' ;
3
- import 'package:dio/adapter.dart' ;
4
-
5
- import 'enums.dart' ;
1
+ part of dart_appwrite;
6
2
7
3
class Client {
8
4
String endPoint;
@@ -17,7 +13,7 @@ class Client {
17
13
18
14
this .headers = {
19
15
'content-type' : 'application/json' ,
20
- 'x-sdk-version' : 'appwrite:dart:0.2 .0' ,
16
+ 'x-sdk-version' : 'appwrite:dart:0.3 .0' ,
21
17
};
22
18
23
19
this .config = {};
@@ -70,7 +66,7 @@ class Client {
70
66
}
71
67
}
72
68
73
- Future <Response > call (HttpMethod method, {String path = '' , Map <String , String > headers = const {}, Map <String , dynamic > params = const {}}) async {
69
+ Future <Response > call (HttpMethod method, {String path = '' , Map <String , String > headers = const {}, Map <String , dynamic > params = const {}, ResponseType responseType }) async {
74
70
if (selfSigned) {
75
71
// Allow self signed requests
76
72
(http.httpClientAdapter as DefaultHttpClientAdapter ).onHttpClientCreate = (HttpClient client) {
@@ -85,20 +81,30 @@ class Client {
85
81
Options options = Options (
86
82
headers: {...this .headers, ...headers},
87
83
method: method.name (),
84
+ responseType: responseType
88
85
);
89
-
90
- if (headers['content-type' ] == 'multipart/form-data' ) {
91
- return http.request (path, data: FormData .fromMap (params), options: options);
92
- }
93
-
94
- if (method == HttpMethod .get ) {
95
- params.keys.forEach ((key) {if (params[key] is int || params[key] is double ) {
96
- params[key] = params[key].toString ();
97
- }});
98
-
99
- return http.get (path, queryParameters: params, options: options);
100
- } else {
101
- return http.request (path, data: params, options: options);
86
+ try {
87
+
88
+ if (headers['content-type' ] == 'multipart/form-data' ) {
89
+ return http.request (path, data: FormData .fromMap (params), options: options);
90
+ }
91
+
92
+ if (method == HttpMethod .get ) {
93
+ params.keys.forEach ((key) {if (params[key] is int || params[key] is double ) {
94
+ params[key] = params[key].toString ();
95
+ }});
96
+
97
+ return http.get (path, queryParameters: params, options: options);
98
+ } else {
99
+ return http.request (path, data: params, options: options);
100
+ }
101
+ } on DioError catch (e) {
102
+ if (e.response == null ) {
103
+ throw AppwriteException (e.message);
104
+ }
105
+ throw AppwriteException (e.response.data['message' ],e.response.data['code' ], e.response.data);
106
+ } catch (e) {
107
+ throw AppwriteException (e.message);
102
108
}
103
109
}
104
110
}
0 commit comments