@@ -5,11 +5,14 @@ import 'package:flutter_feathersjs/src/featherjs_client_base.dart';
55import 'package:flutter_feathersjs/src/utils.dart' ;
66import 'package:meta/meta.dart' ;
77
8+ import 'constants.dart' ;
9+
810/// Feathers Js rest client for rest api call
911class RestClient extends FlutterFeathersjs {
1012 ///Dio as http client
1113 Dio dio;
1214 Utils utils;
15+ Constants isCode;
1316
1417 //Using singleton to ensure we the same instance of it
1518 static final RestClient _restClient = RestClient ._internal ();
@@ -88,23 +91,23 @@ class RestClient extends FlutterFeathersjs {
8891 print ("jwt expired or jwt malformed" );
8992 authResponse["error" ] = true ;
9093 authResponse["message" ] = "jwt expired" ;
91- authResponse["error_zone" ] = " JWT_EXPIRED_ERROR" ;
94+ authResponse["error_zone" ] = isCode.. JWT_EXPIRED_ERROR ;
9295 } else if (response.statusCode == 200 ) {
9396 print ("Jwt still validated" );
9497 authResponse["error" ] = false ;
9598 authResponse["message" ] = "Jwt still validated" ;
96- authResponse["error_zone" ] = " NO_ERROR" ;
99+ authResponse["error_zone" ] = isCode. NO_ERROR ;
97100 } else {
98101 print ("Unknown error" );
99102 authResponse["error" ] = true ;
100103 authResponse["message" ] = "Unknown error" ;
101- authResponse["error_zone" ] = " UNKNOWN_ERROR" ;
104+ authResponse["error_zone" ] = isCode. UNKNOWN_ERROR ;
102105 }
103106 } catch (e) {
104107 print ("Unable to connect to the server" );
105108 authResponse["error" ] = true ;
106109 authResponse["message" ] = e;
107- authResponse["error_zone" ] = " JWT_ERROR" ;
110+ authResponse["error_zone" ] = isCode. JWT_ERROR ;
108111 }
109112 }
110113
@@ -113,7 +116,7 @@ class RestClient extends FlutterFeathersjs {
113116 print ("No old token found. Must reAuth user" );
114117 authResponse["error" ] = true ;
115118 authResponse["message" ] = "No old token found. Must reAuth user" ;
116- authResponse["error_zone" ] = " JWT_NOT_FOUND" ;
119+ authResponse["error_zone" ] = isCode. JWT_NOT_FOUND ;
117120 }
118121 asyncTask.complete (authResponse);
119122 return asyncTask.future;
@@ -139,16 +142,16 @@ class RestClient extends FlutterFeathersjs {
139142 //This is useful to display to end user why auth failed
140143 //With 401: it will be either Invalid credentials or strategy error
141144 if (response.data["message" ] == "Invalid login" ) {
142- authResponse["error_zone" ] = " INVALID_CREDENTIALS" ;
145+ authResponse["error_zone" ] = isCode. INVALID_CREDENTIALS ;
143146 } else {
144- authResponse["error_zone" ] = " INVALID_STRATEGY" ;
147+ authResponse["error_zone" ] = isCode. INVALID_STRATEGY ;
145148 }
146149 authResponse["error" ] = true ;
147150 authResponse["message" ] = response.data["message" ];
148151 } else if (response.data['accessToken' ] != null ) {
149152 authResponse["error" ] = false ;
150153 authResponse["message" ] = response.data["user" ];
151- authResponse["error_zone" ] = " NO_ERROR" ;
154+ authResponse["error_zone" ] = isCode. NO_ERROR ;
152155
153156 //Storing the token
154157 utils.setAccessToken (token: response.data['accessToken' ]);
@@ -161,7 +164,7 @@ class RestClient extends FlutterFeathersjs {
161164 //Error caught by Dio
162165 authResponse["error" ] = true ;
163166 authResponse["message" ] = e;
164- authResponse["error_zone" ] = " DIO_ERROR" ;
167+ authResponse["error_zone" ] = isCode. DIO_ERROR ;
165168 }
166169 //Send response
167170 asyncTask.complete (authResponse);
0 commit comments