11import 'dart:async' ;
22
33import 'package:dio/dio.dart' ;
4+ import 'package:flutter_feathersjs/src/constants.dart' ;
45import 'package:flutter_feathersjs/src/featherjs_client_base.dart' ;
56import 'package:flutter_feathersjs/src/utils.dart' ;
67import 'package:meta/meta.dart' ;
78
8- import 'constants.dart' ;
9-
109/// Feathers Js rest client for rest api call
1110class RestClient extends FlutterFeathersjs {
1211 ///Dio as http client
1312 Dio dio;
1413 Utils utils;
15- Constants isCode;
1614
1715 //Using singleton to ensure we the same instance of it
1816 static final RestClient _restClient = RestClient ._internal ();
@@ -53,7 +51,8 @@ class RestClient extends FlutterFeathersjs {
5351 // print(e.response.request);
5452 //Only send the error message from feathers js server not for Dio
5553 print (e.response.data);
56- return e.response.data; //continue
54+ return dio.resolve (e.response.data);
55+ //return e.response.data; //continue
5756 } else {
5857 // Something happened in setting up or sending the request that triggered an Error
5958 // print(e.request);
@@ -91,23 +90,23 @@ class RestClient extends FlutterFeathersjs {
9190 print ("jwt expired or jwt malformed" );
9291 authResponse["error" ] = true ;
9392 authResponse["message" ] = "jwt expired" ;
94- authResponse["error_zone" ] = isCode. .JWT_EXPIRED_ERROR ;
93+ authResponse["error_zone" ] = Constants .JWT_EXPIRED_ERROR ;
9594 } else if (response.statusCode == 200 ) {
9695 print ("Jwt still validated" );
9796 authResponse["error" ] = false ;
9897 authResponse["message" ] = "Jwt still validated" ;
99- authResponse["error_zone" ] = isCode .NO_ERROR ;
98+ authResponse["error_zone" ] = Constants .NO_ERROR ;
10099 } else {
101100 print ("Unknown error" );
102101 authResponse["error" ] = true ;
103102 authResponse["message" ] = "Unknown error" ;
104- authResponse["error_zone" ] = isCode .UNKNOWN_ERROR ;
103+ authResponse["error_zone" ] = Constants .UNKNOWN_ERROR ;
105104 }
106105 } catch (e) {
107106 print ("Unable to connect to the server" );
108107 authResponse["error" ] = true ;
109108 authResponse["message" ] = e;
110- authResponse["error_zone" ] = isCode .JWT_ERROR ;
109+ authResponse["error_zone" ] = Constants .JWT_ERROR ;
111110 }
112111 }
113112
@@ -116,7 +115,7 @@ class RestClient extends FlutterFeathersjs {
116115 print ("No old token found. Must reAuth user" );
117116 authResponse["error" ] = true ;
118117 authResponse["message" ] = "No old token found. Must reAuth user" ;
119- authResponse["error_zone" ] = isCode .JWT_NOT_FOUND ;
118+ authResponse["error_zone" ] = Constants .JWT_NOT_FOUND ;
120119 }
121120 asyncTask.complete (authResponse);
122121 return asyncTask.future;
@@ -142,16 +141,16 @@ class RestClient extends FlutterFeathersjs {
142141 //This is useful to display to end user why auth failed
143142 //With 401: it will be either Invalid credentials or strategy error
144143 if (response.data["message" ] == "Invalid login" ) {
145- authResponse["error_zone" ] = isCode .INVALID_CREDENTIALS ;
144+ authResponse["error_zone" ] = Constants .INVALID_CREDENTIALS ;
146145 } else {
147- authResponse["error_zone" ] = isCode .INVALID_STRATEGY ;
146+ authResponse["error_zone" ] = Constants .INVALID_STRATEGY ;
148147 }
149148 authResponse["error" ] = true ;
150149 authResponse["message" ] = response.data["message" ];
151150 } else if (response.data['accessToken' ] != null ) {
152151 authResponse["error" ] = false ;
153152 authResponse["message" ] = response.data["user" ];
154- authResponse["error_zone" ] = isCode .NO_ERROR ;
153+ authResponse["error_zone" ] = Constants .NO_ERROR ;
155154
156155 //Storing the token
157156 utils.setAccessToken (token: response.data['accessToken' ]);
@@ -164,7 +163,7 @@ class RestClient extends FlutterFeathersjs {
164163 //Error caught by Dio
165164 authResponse["error" ] = true ;
166165 authResponse["message" ] = e;
167- authResponse["error_zone" ] = isCode .DIO_ERROR ;
166+ authResponse["error_zone" ] = Constants .DIO_ERROR ;
168167 }
169168 //Send response
170169 asyncTask.complete (authResponse);
0 commit comments