Skip to content

Commit 5cfc86b

Browse files
committed
fix const error
1 parent e7df1bb commit 5cfc86b

File tree

5 files changed

+32
-34
lines changed

5 files changed

+32
-34
lines changed

lib/flutter_feathersjs.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class FlutterFeathersjs {
1111
RestClient rest;
1212
//SocketioClient
1313
SocketioClient scketio;
14-
Constants isCode;
1514

1615
///Using singleton
1716
static final FlutterFeathersjs _flutterFeathersjs =
@@ -60,7 +59,7 @@ class FlutterFeathersjs {
6059
//Hold global auth infos
6160
Map<String, dynamic> authResponse = {
6261
"error": true,
63-
"error_zone": isCode.UNKNOWN_ERROR,
62+
"error_zone": Constants.UNKNOWN_ERROR,
6463
"message": "An error occured either on rest or socketio auth",
6564
"restResponse": {},
6665
"scketResponse": {}
@@ -74,11 +73,11 @@ class FlutterFeathersjs {
7473
//Finally send response
7574
if (!restAuthResponse["error"] && !socketioAuthResponse["error"]) {
7675
authResponse["error"] = false;
77-
authResponse["error_zone"] = isCode.BOTH_CLIENT_AUTHED;
76+
authResponse["error_zone"] = Constants.BOTH_CLIENT_AUTHED;
7877
authResponse["message"] = socketioAuthResponse;
7978
} else {
8079
authResponse["error"] = true;
81-
authResponse["error_zone"] = isCode.ONE_OR_BOTH_CLIENT_NOT_AUTHED;
80+
authResponse["error_zone"] = Constants.ONE_OR_BOTH_CLIENT_NOT_AUTHED;
8281
authResponse["message"] =
8382
"One or both client is(are) not authed. Please checkout restResponse field or scketResponse field for more infos.";
8483
authResponse["restResponse"] = restAuthResponse;

lib/src/constants.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
class Constants {
2-
final INVALID_CREDENTIALS = "INVALID_CREDENTIALS";
3-
final JWT_EXPIRED_ERROR = "JWT_EXPIRED_ERROR";
4-
final NO_ERROR = "NO_ERROR";
5-
final UNKNOWN_ERROR = "UNKNOWN_ERROR";
6-
final JWT_ERROR = "JWT_ERROR";
7-
final JWT_NOT_FOUND = "JWT_NOT_FOUND";
8-
final INVALID_STRATEGY = "INVALID_STRATEGY";
9-
final DIO_ERROR = "DIO_ERROR";
2+
static const String INVALID_CREDENTIALS = "INVALID_CREDENTIALS";
3+
static const String JWT_EXPIRED_ERROR = "JWT_EXPIRED_ERROR";
4+
static const String NO_ERROR = "NO_ERROR";
5+
static const String UNKNOWN_ERROR = "UNKNOWN_ERROR";
6+
static const String JWT_ERROR = "JWT_ERROR";
7+
static const String JWT_NOT_FOUND = "JWT_NOT_FOUND";
8+
static const String INVALID_STRATEGY = "INVALID_STRATEGY";
9+
static const String DIO_ERROR = "DIO_ERROR";
1010

11-
final AUTH_WITH_JWT_SUCCEED = "AUTH_WITH_JWT_SUCCEED";
12-
final AUTH_WITH_JWT_FAILED = "AUTH_WITH_JWT_FAILED";
11+
static const String AUTH_WITH_JWT_SUCCEED = "AUTH_WITH_JWT_SUCCEED";
12+
static const String AUTH_WITH_JWT_FAILED = "AUTH_WITH_JWT_FAILED";
1313

14-
final BOTH_CLIENT_AUTHED = "BOTH_CLIENT_AUTHED";
15-
final ONE_OR_BOTH_CLIENT_NOT_AUTHED = "ONE_OR_BOTH_CLIENT_NOT_AUTHED";
14+
static const String BOTH_CLIENT_AUTHED = "BOTH_CLIENT_AUTHED";
15+
static const String ONE_OR_BOTH_CLIENT_NOT_AUTHED = "ONE_OR_BOTH_CLIENT_NOT_AUTHED";
1616
}

lib/src/rest_client.dart

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import 'dart:async';
22

33
import 'package:dio/dio.dart';
4+
import 'package:flutter_feathersjs/src/constants.dart';
45
import 'package:flutter_feathersjs/src/featherjs_client_base.dart';
56
import 'package:flutter_feathersjs/src/utils.dart';
67
import 'package:meta/meta.dart';
78

8-
import 'constants.dart';
9-
109
/// Feathers Js rest client for rest api call
1110
class 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);

lib/src/scketio_client.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class SocketioClient extends FlutterFeathersjs {
1111
IO.Socket _socket;
1212
bool dev = true;
1313
Utils utils;
14-
Constants isCode;
14+
Constants Constants;
1515

1616
//Using singleton
1717
static final SocketioClient _socketioClient = SocketioClient._internal();
@@ -69,7 +69,7 @@ class SocketioClient extends FlutterFeathersjs {
6969

7070
Map<String, dynamic> authResponse = {
7171
"error": true,
72-
"error_zone": isCode.UNKNOWN_ERROR,
72+
"error_zone": Constants.UNKNOWN_ERROR,
7373
"message": "An error occured"
7474
};
7575
Completer asyncTask = Completer<dynamic>();
@@ -90,7 +90,7 @@ class SocketioClient extends FlutterFeathersjs {
9090
//Auth is ok
9191
authResponse["error"] = false;
9292
authResponse["message"] = dataResponse[1];
93-
authResponse["error_zone"] = isCode.AUTH_WITH_JWT_SUCCEED;
93+
authResponse["error_zone"] = Constants.AUTH_WITH_JWT_SUCCEED;
9494

9595
//Every emit or on will be authed
9696
this._socket.io.options['extraHeaders'] = {
@@ -101,7 +101,7 @@ class SocketioClient extends FlutterFeathersjs {
101101
//Auth is not ok
102102
authResponse["error"] = true;
103103
authResponse["message"] = dataResponse;
104-
authResponse["error_zone"] = isCode.AUTH_WITH_JWT_FAILED;
104+
authResponse["error_zone"] = Constants.AUTH_WITH_JWT_FAILED;
105105
}
106106
asyncTask.complete(authResponse);
107107
});

test/feathersjs_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void main() async {
5353
print(reps["message"]);
5454
print("----------Authed user :------");
5555
} else if (reps["error_zone"] ==
56-
flutterFeathersjs.isCode.BOTH_CLIENT_AUTHED)
56+
flutterFeathersjs.Constants.BOTH_CLIENT_AUTHED)
5757
print("Blabal");
5858
else {
5959
print(reps["error_zone"]);

0 commit comments

Comments
 (0)