Skip to content

Commit f76cce8

Browse files
committed
Fix overwhelming debug's message ouputing in production
1 parent d02d981 commit f76cce8

File tree

7 files changed

+268
-124
lines changed

7 files changed

+268
-124
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## 1.0.10
2+
Fix [overwhelming debug's message ouputing in production](https://github.com/Dahkenangnon/flutter_feathersjs.dart/discussions/6#discussion-2051014)
13
## 1.0.9
24

35
Documentation is now available from: [https://dahkenangnon.github.io/flutter_feathersjs.dart/](https://dahkenangnon.github.io/flutter_feathersjs.dart/)

docs/src/guide/README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,34 @@ Communicate with your feathers js [https://feathersjs.com/](https://feathersjs.c
66

77
`Infos: Feathers js is a node framework for real-time applications and REST APIs.`
88

9-
109
*__FormData support out the box, auth, reAuth, socketio send event, rest ...__
1110

11+
## Illustration's service infos
12+
13+
In this documentation, we assume that our feathers js api has a **news** services register on **/news**
14+
15+
with the following schema
16+
17+
```js
18+
19+
// News schema
20+
const schema = new Schema({
21+
22+
title: { type: String, required: true },
23+
24+
content: { type: String, required: true },
25+
26+
// They can provide multiple image for a single news
27+
files: { type: Array, required: false },
28+
29+
//The publisher id
30+
author: { type: Schema.Types.ObjectId, ref: 'users', required: true },
31+
32+
}, {
33+
timestamps: true
34+
});
35+
```
1236

13-
NB: I'm working on this doc and an example app which will be available very soon.
37+
## The illustration's app
1438

15-
:warning: This Doc is still dev, so it can contain some misspelled.
39+
The app used for this documentation will be available very soon.

docs/src/guide/using-rest.md

Lines changed: 147 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,149 @@
11
# Rest methods
22

3-
This is coming soon.
3+
**__Feathers Js rest client for rest api call__**
4+
5+
You get exactly what feathers server send (*Serialization and Deserialization are not supported.*)
6+
You can get the response sent by feathers js by: response.data
7+
When required, to access the data property of feathers response, you have to do: response.data.data
8+
9+
## find
10+
11+
Retrieves a list of all matching resources from the service
12+
13+
All news
14+
15+
```dart
16+
// Find all news
17+
var newsResponse = await flutterFeathersjs.rest.find(serviceName: "news");
18+
print(newsResponse.data);
19+
```
20+
21+
News matching certain query
22+
23+
```dart
24+
// Find news with query: here with {"_id": "5f7643f0462f4348970cd32e"}
25+
var newsResponse = await flutterFeathersjs.rest.find(serviceName: "news", query: {"_id": "5f7643f0462f4348970cd32e"});
26+
print(newsResponse.data);
27+
```
28+
29+
## get
30+
31+
Retrieve a single resource from the service with an `_id`
32+
33+
```dart
34+
// Get a single new with it _id
35+
var newsResponse = await flutterFeathersjs.rest.get(serviceName: "news", objectId: "5f7643f0462f4348970cd32e");
36+
print(newsResponse.data);
37+
```
38+
39+
## create
40+
41+
Create a new resource with data.
42+
43+
Without files
44+
45+
```dart
46+
// Create a news on the server without file upload
47+
var newsResponse = await flutterFeathersjs.rest.create(
48+
serviceName: "news",
49+
data: {"title": "Using FlutterFeathersjs is easy", "content": "Yes very easy" , "author" :"5f7h43f0462f4348970cd32e"});
50+
```
51+
52+
With files
53+
54+
```dart
55+
// Create a news on the server with file upload
56+
// For this, it is your responsability to configure your feathers js to handle
57+
// file upload, see multer for example
58+
59+
//1. Afther picking filed from devices, ensure you have a list of File object as:
60+
var files = [{ 'filePath': '/data/shared/image.png', 'fileName': 'image.png' },
61+
{ 'filePath': '/data/shared/image.png', 'fileName': 'image.png' }];
62+
63+
//2. Send data with files
64+
var newsResponse = await flutterFeathersjs.rest.create(
65+
serviceName: "news",
66+
data: {"title": "Using FlutterFeathersjs is easy even with file upload", "content": "Yes very easy" , "author" :"5f7h43f0462f4348970cd32e"},
67+
containsFile = true,
68+
fileFieldName = "files", // See the news schema. This is the same string
69+
);
70+
```
71+
72+
## update
73+
74+
Completely replace a single resource with the `_id = objectId`
75+
76+
Without files
77+
78+
```dart
79+
// Update a news on the server without file upload
80+
var newsResponse = await flutterFeathersjs.rest.update(
81+
objectId: "5f7h43f0462f4t48970cd32e",
82+
serviceName: "news",
83+
data: {"title": "Using FlutterFeathersjs is easy", "content": "Yes very easy" , "author" :"5f7h43f0462f4348970cd32e"});
84+
```
85+
86+
With files
87+
88+
```dart
89+
// Create a news on the server with file upload
90+
// For this, it is your responsability to configure your feathers js to handle
91+
// file upload, see multer
92+
93+
//1. Afther picking file from devices, ensure you have a list of File object as:
94+
var files = [{ 'filePath': '/data/shared/image.png', 'fileName': 'image.png' },
95+
{ 'filePath': '/data/shared/image.png', 'fileName': 'image.png' }];
96+
97+
//2. Send data with file
98+
var newsResponse = await flutterFeathersjs.rest.update(
99+
objectId: "5f7h43f0462f4t48970cd32e",
100+
serviceName: "news",
101+
data: {"title": "Using FlutterFeathersjs is easy even with file upload", "content": "Yes very easy" , "author" :"5f7h43f0462f4348970cd32e"},
102+
containsFile = true,
103+
fileFieldName = "files", // See the news schema. This is the same string
104+
);
105+
```
106+
107+
## patch
108+
109+
Completely replace a single resource with the `_id = objectId`
110+
111+
Without files
112+
113+
```dart
114+
// Patch a new on the server without file upload
115+
var newsResponse = await flutterFeathersjs.rest.patch(
116+
objectId: "5f7h43f0462f4t48970cd32e",
117+
serviceName: "news",
118+
data: {"title": "Using FlutterFeathersjs is easy", "content": "Yes very easy" , "author" :"5f7h43f0462f4348970cd32e"});
119+
```
120+
121+
With files
122+
123+
```dart
124+
// Patch a news on the server with file upload
125+
// For this, it is your responsability to configure your feathers js to handle
126+
// file upload, see multer
127+
128+
//1. Afther picking file from devices, ensure you have a list of File object as:
129+
var files = [{ 'filePath': '/data/shared/image.png', 'fileName': 'image.png' },
130+
{ 'filePath': '/data/shared/image.png', 'fileName': 'image.png' }];
131+
132+
//2. Send data with file
133+
var newsResponse = await flutterFeathersjs.rest.patch(
134+
objectId: "5f7h43f0462f4t48970cd32e",
135+
serviceName: "news",
136+
data: {"title": "Using FlutterFeathersjs is easy even with file upload", "content": "Yes very easy" , "author" :"5f7h43f0462f4348970cd32e"},
137+
containsFile = true,
138+
fileFieldName = "files", // See the news schema. This is the same string
139+
);
140+
```
141+
142+
## remove
143+
144+
Remove a single resource with `_id = objectId`:
145+
146+
```dart
147+
// Remove a news
148+
var newsResponse = await flutterFeathersjs.rest.remove(serviceName: "news", objectId: "5f7643f0462f4348970cd32e");
149+
```

lib/flutter_feathersjs.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,6 @@ class FlutterFeathersjs {
4949

5050
///Intialize both rest and scoketio client
5151
init({@required String baseUrl, Map<String, dynamic> extraHeaders}) {
52-
// if (Foundation.kReleaseMode) {
53-
// // W're on release mode
54-
// dev = false;
55-
// } else {
56-
// // W're not on release mode
57-
// dev = true;
58-
// }
59-
6052
rest = new RestClient()..init(baseUrl: baseUrl, extraHeaders: extraHeaders);
6153

6254
scketio = new SocketioClient()..init(baseUrl: baseUrl);

lib/src/rest_client.dart

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:flutter_feathersjs/src/constants.dart';
55
import 'package:flutter_feathersjs/src/featherjs_client_base.dart';
66
import 'package:flutter_feathersjs/src/utils.dart';
77
import 'package:meta/meta.dart';
8+
import 'package:flutter/foundation.dart' as Foundation;
89

910
///
1011
///Feathers Js rest client for rest api call
@@ -58,19 +59,24 @@ class RestClient extends FlutterFeathersjs {
5859
// Do something with response error
5960

6061
if (e.response != null) {
61-
print(e.response.data);
62-
print(e.response.headers);
63-
print(e.response.request);
64-
//Only send the error message from feathers js server not for Dio
65-
print(e.response);
62+
if (!Foundation.kReleaseMode) {
63+
print(e.response.data);
64+
print(e.response.headers);
65+
print(e.response.request);
66+
//Only send the error message from feathers js server not for Dio
67+
print(e.response);
68+
}
69+
6670
return dio.resolve(e.response.data);
6771
//return e.response.data; //continue
6872
} else {
69-
// Something happened in setting up or sending the request that triggered an Error
70-
print(e.request);
71-
print(e.message);
72-
//By returning null, it means that error is from client
73-
//return null;
73+
if (!Foundation.kReleaseMode) {
74+
// Something happened in setting up or sending the request that triggered an Error
75+
print(e.request);
76+
print(e.message);
77+
//By returning null, it means that error is from client
78+
//return null;
79+
}
7480
return e;
7581
}
7682
}));
@@ -98,26 +104,37 @@ class RestClient extends FlutterFeathersjs {
98104
var response = await this
99105
.dio
100106
.get("/$serviceName", queryParameters: {"\$limit": 1});
101-
print(response);
107+
if (!Foundation.kReleaseMode) {
108+
print(response);
109+
}
102110

103111
if (response.statusCode == 401) {
104-
print("jwt expired or jwt malformed");
112+
if (!Foundation.kReleaseMode) {
113+
print("jwt expired or jwt malformed");
114+
}
115+
105116
authResponse["error"] = true;
106117
authResponse["message"] = "jwt expired";
107118
authResponse["error_zone"] = Constants.JWT_EXPIRED_ERROR;
108119
} else if (response.statusCode == 200) {
109-
print("Jwt still validated");
120+
if (!Foundation.kReleaseMode) {
121+
print("Jwt still validated");
122+
}
110123
authResponse["error"] = false;
111124
authResponse["message"] = "Jwt still validated";
112125
authResponse["error_zone"] = Constants.NO_ERROR;
113126
} else {
114-
print("Unknown error");
127+
if (!Foundation.kReleaseMode) {
128+
print("Unknown error");
129+
}
115130
authResponse["error"] = true;
116131
authResponse["message"] = "Unknown error";
117132
authResponse["error_zone"] = Constants.UNKNOWN_ERROR;
118133
}
119134
} catch (e) {
120-
print("Unable to connect to the server");
135+
if (!Foundation.kReleaseMode) {
136+
print("Unable to connect to the server");
137+
}
121138
authResponse["error"] = true;
122139
authResponse["message"] = e;
123140
authResponse["error_zone"] = Constants.JWT_ERROR;
@@ -126,7 +143,9 @@ class RestClient extends FlutterFeathersjs {
126143

127144
///No token is found
128145
else {
129-
print("No old token found. Must reAuth user");
146+
if (!Foundation.kReleaseMode) {
147+
print("No old token found. Must reAuth user");
148+
}
130149
authResponse["error"] = true;
131150
authResponse["message"] = "No old token found. Must reAuth user";
132151
authResponse["error_zone"] = Constants.JWT_NOT_FOUND;
@@ -207,8 +226,8 @@ class RestClient extends FlutterFeathersjs {
207226
try {
208227
response = await this.dio.get("/$serviceName", queryParameters: query);
209228
} catch (e) {
210-
print("Error in rest::find");
211-
print(e);
229+
// print("Error in rest::find");
230+
// print(e);
212231
}
213232
return response;
214233
}
@@ -223,8 +242,8 @@ class RestClient extends FlutterFeathersjs {
223242
try {
224243
response = response = await this.dio.get("/$serviceName/$objectId");
225244
} catch (e) {
226-
print("Error in rest::get");
227-
print(e);
245+
// print("Error in rest::get");
246+
// print(e);
228247
}
229248
return response;
230249
}
@@ -261,16 +280,16 @@ class RestClient extends FlutterFeathersjs {
261280
Response<dynamic> response;
262281

263282
if (!containsFile) {
264-
print('Dio.post without file');
265-
print("Service name is");
266-
print(serviceName);
267-
print("Data are: ");
268-
print(data);
283+
// print('Dio.post without file');
284+
// print("Service name is");
285+
// print(serviceName);
286+
// print("Data are: ");
287+
// print(data);
269288
try {
270289
response = await this.dio.post("/$serviceName", data: data);
271-
print("Response from server is:");
272-
print(response.data);
273-
print(response);
290+
// print("Response from server is:");
291+
// print(response.data);
292+
// print(response);
274293
} catch (e) {
275294
print("Error in rest::create");
276295
print(e);
@@ -453,36 +472,21 @@ class RestClient extends FlutterFeathersjs {
453472
@required fileFieldName,
454473
List<Map<String, String>> files}) async {
455474
Map<String, dynamic> data = {};
456-
print("Inside makeFormData");
457-
print("nonFilesFieldsMap is ");
458-
print(nonFilesFieldsMap);
475+
476+
if (!Foundation.kReleaseMode) {
477+
print("Inside makeFormData");
478+
print("nonFilesFieldsMap is ");
479+
print(nonFilesFieldsMap);
480+
}
481+
459482
// Non file
460483
if (nonFilesFieldsMap != null) {
461484
print("nonFilesFieldsMap is not null ");
462485
nonFilesFieldsMap.forEach((key, value) {
463486
data["$key"] = value;
464487
});
465488
}
466-
print("nonFilesFieldsMap withoud the files is ");
467-
print(data);
468489
var formData = FormData.fromMap(data);
469-
// // If single file is send
470-
// if (files != null && files.length == 1) {
471-
// print("Receive signle file");
472-
// var fileData = files[0];
473-
// var file = await MultipartFile.fromFile(fileData["filePath"],
474-
// filename: fileData["fileName"]);
475-
// data["$fileFieldName"] = file;
476-
// } else if (files != null && files.length >= 1) {
477-
// print("Receive multiple file");
478-
// List filesList = [];
479-
// for (var fileData in files) {
480-
// var file = await MultipartFile.fromFile(fileData["filePath"],
481-
// filename: fileData["fileName"]);
482-
// filesList.add(file);
483-
// }
484-
// data["$fileFieldName"] = filesList;
485-
// }
486490
for (var fileData in files) {
487491
formData.files.add(MapEntry(
488492
fileFieldName,

0 commit comments

Comments
 (0)