Skip to content

Commit 2542178

Browse files
authored
fix: Dio error holds a reference to null values (#825)
1 parent b07ce8c commit 2542178

File tree

4 files changed

+53
-18
lines changed

4 files changed

+53
-18
lines changed

packages/dart/CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [3.1.14](https://github.com/parse-community/Parse-SDK-Flutter/compare/dart-3.1.13...dart-3.1.14) (2023-02-26)
2+
3+
### Bug Fixes
4+
5+
* Dio error object holds a reference to null values ([#774](https://github.com/parse-community/Parse-SDK-Flutter/issues/774))
6+
17
## [3.1.13](https://github.com/parse-community/Parse-SDK-Flutter/compare/dart-3.1.12...dart-3.1.13) (2023-02-15)
28

39
### Bug Fixes
@@ -161,7 +167,7 @@ Bug fixes
161167
## 1.0.22
162168

163169
Added dirty children
164-
Added option of sembast or share_preferences
170+
Added option of sembast or share_preferences
165171

166172
## 1.0.21
167173

@@ -183,7 +189,7 @@ Bug fix
183189

184190
## 1.0.17
185191

186-
LiveQuery fix
192+
LiveQuery fix
187193
Bug fixes
188194

189195
## 1.0.16

packages/dart/lib/src/base/parse_constants.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
part of flutter_parse_sdk;
22

33
// Library
4-
const String keySdkVersion = '3.1.13';
4+
const String keySdkVersion = '3.1.14';
55
const String keyLibraryName = 'Flutter Parse SDK';
66

77
// End Points

packages/dart/lib/src/network/parse_dio_client.dart

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ class ParseDioClient extends ParseClient {
2727
path,
2828
options: _Options(headers: options?.headers),
2929
);
30+
3031
return ParseNetworkResponse(
31-
data: dioResponse.data!, statusCode: dioResponse.statusCode!);
32+
data: dioResponse.data!,
33+
statusCode: dioResponse.statusCode!,
34+
);
3235
} on dio.DioError catch (error) {
3336
return ParseNetworkResponse(
34-
data: error.response?.data, statusCode: error.response!.statusCode!);
37+
data: error.response?.data ?? _fallbackErrorData,
38+
statusCode: error.response?.statusCode ?? ParseError.otherCause,
39+
);
3540
}
3641
}
3742

@@ -51,12 +56,15 @@ class ParseDioClient extends ParseClient {
5156
headers: options?.headers, responseType: dio.ResponseType.bytes),
5257
);
5358
return ParseNetworkByteResponse(
54-
bytes: dioResponse.data, statusCode: dioResponse.statusCode!);
59+
bytes: dioResponse.data,
60+
statusCode: dioResponse.statusCode!,
61+
);
5562
} on dio.DioError catch (error) {
5663
if (error.response != null) {
5764
return ParseNetworkByteResponse(
58-
data: error.response?.data,
59-
statusCode: error.response!.statusCode!);
65+
data: error.response?.data ?? _fallbackErrorData,
66+
statusCode: error.response?.statusCode ?? ParseError.otherCause,
67+
);
6068
} else {
6169
return _getOtherCaseErrorForParseNetworkResponse(error.error);
6270
}
@@ -72,11 +80,16 @@ class ParseDioClient extends ParseClient {
7280
data: data,
7381
options: _Options(headers: options?.headers),
7482
);
83+
7584
return ParseNetworkResponse(
76-
data: dioResponse.data!, statusCode: dioResponse.statusCode!);
85+
data: dioResponse.data!,
86+
statusCode: dioResponse.statusCode!,
87+
);
7788
} on dio.DioError catch (error) {
7889
return ParseNetworkResponse(
79-
data: error.response?.data, statusCode: error.response!.statusCode!);
90+
data: error.response?.data ?? _fallbackErrorData,
91+
statusCode: error.response?.statusCode ?? ParseError.otherCause,
92+
);
8093
}
8194
}
8295

@@ -89,11 +102,16 @@ class ParseDioClient extends ParseClient {
89102
data: data,
90103
options: _Options(headers: options?.headers),
91104
);
105+
92106
return ParseNetworkResponse(
93-
data: dioResponse.data!, statusCode: dioResponse.statusCode!);
107+
data: dioResponse.data!,
108+
statusCode: dioResponse.statusCode!,
109+
);
94110
} on dio.DioError catch (error) {
95111
return ParseNetworkResponse(
96-
data: error.response?.data, statusCode: error.response!.statusCode!);
112+
data: error.response?.data ?? _fallbackErrorData,
113+
statusCode: error.response?.statusCode ?? ParseError.otherCause,
114+
);
97115
}
98116
}
99117

@@ -111,13 +129,17 @@ class ParseDioClient extends ParseClient {
111129
options: _Options(headers: options?.headers),
112130
onSendProgress: onSendProgress,
113131
);
132+
114133
return ParseNetworkResponse(
115-
data: dioResponse.data!, statusCode: dioResponse.statusCode!);
134+
data: dioResponse.data!,
135+
statusCode: dioResponse.statusCode!,
136+
);
116137
} on dio.DioError catch (error) {
117138
if (error.response != null) {
118139
return ParseNetworkResponse(
119-
data: error.response?.data,
120-
statusCode: error.response!.statusCode!);
140+
data: error.response?.data ?? _fallbackErrorData,
141+
statusCode: error.response?.statusCode ?? ParseError.otherCause,
142+
);
121143
} else {
122144
return _getOtherCaseErrorForParseNetworkResponse(error.error);
123145
}
@@ -138,13 +160,20 @@ class ParseDioClient extends ParseClient {
138160
path,
139161
options: _Options(headers: options?.headers),
140162
);
163+
141164
return ParseNetworkResponse(
142-
data: dioResponse.data!, statusCode: dioResponse.statusCode!);
165+
data: dioResponse.data!,
166+
statusCode: dioResponse.statusCode!,
167+
);
143168
} on dio.DioError catch (error) {
144169
return ParseNetworkResponse(
145-
data: error.response?.data, statusCode: error.response!.statusCode!);
170+
data: error.response?.data ?? _fallbackErrorData,
171+
statusCode: error.response?.statusCode ?? ParseError.otherCause,
172+
);
146173
}
147174
}
175+
176+
String get _fallbackErrorData => '{"$keyError":"NetworkError"}';
148177
}
149178

150179
/// Creates a custom version of HTTP Client that has Parse Data Preset

packages/dart/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: parse_server_sdk
22
description: Dart plugin for Parse Server, (https://parseplatform.org), (https://back4app.com)
3-
version: 3.1.13
3+
version: 3.1.14
44
homepage: https://github.com/parse-community/Parse-SDK-Flutter
55

66
environment:

0 commit comments

Comments
 (0)