diff --git a/packages/dart/CHANGELOG.md b/packages/dart/CHANGELOG.md index ecd6bc544..5997ab3a4 100644 --- a/packages/dart/CHANGELOG.md +++ b/packages/dart/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.0.1 +Fixed network exceptions. [#482](https://github.com/parse-community/Parse-SDK-Flutter/pull/482) + ## 2.0.0 ##### Warning: This release contains breaking changes. If you are using flutter you should migrate using *[this](https://github.com/parse-community/Parse-SDK-Flutter/blob/release/2.0.0/docs/migrate-2-0-0.md)* guide. diff --git a/packages/dart/README.md b/packages/dart/README.md index 268705072..9705e8d2a 100644 --- a/packages/dart/README.md +++ b/packages/dart/README.md @@ -20,7 +20,7 @@ This is a work in progress and we are consistently updating it. Please let us kn To install, either add to your pubspec.yaml ```yml dependencies: - parse_server_sdk: ^2.0.0 + parse_server_sdk: ^2.0.1 ``` or clone this repository and add to your project. As this is an early development with multiple contributors, it is probably best to download/clone and keep updating as an when a new feature is added. diff --git a/packages/dart/lib/src/base/parse_constants.dart b/packages/dart/lib/src/base/parse_constants.dart index d60d0daed..b34c4d0bb 100644 --- a/packages/dart/lib/src/base/parse_constants.dart +++ b/packages/dart/lib/src/base/parse_constants.dart @@ -1,7 +1,7 @@ part of flutter_parse_sdk; // Library -const String keySdkVersion = '2.0.0'; +const String keySdkVersion = '2.0.1'; const String keyLibraryName = 'Flutter Parse SDK'; // End Points diff --git a/packages/dart/lib/src/objects/parse_function.dart b/packages/dart/lib/src/objects/parse_function.dart index 71afd0fff..81b396bee 100644 --- a/packages/dart/lib/src/objects/parse_function.dart +++ b/packages/dart/lib/src/objects/parse_function.dart @@ -32,12 +32,15 @@ class ParseCloudFunction extends ParseObject { if (parameters != null) { _setObjectData(parameters); } - - final Response result = await _client.post(uri, - options: Options(headers: headers), - data: json.encode(_getObjectData())); - return handleResponse( - this, result, ParseApiRQ.execute, _debug, parseClassName); + try { + final Response result = await _client.post(uri, + options: Options(headers: headers), + data: json.encode(_getObjectData())); + return handleResponse( + this, result, ParseApiRQ.execute, _debug, parseClassName); + } on Exception catch (e) { + return handleException(e, ParseApiRQ.execute, _debug, parseClassName); + } } /// Executes a cloud function that returns a ParseObject type @@ -49,10 +52,15 @@ class ParseCloudFunction extends ParseObject { if (parameters != null) { _setObjectData(parameters); } - final Response result = await _client.post(uri, - options: Options(headers: headers), - data: json.encode(_getObjectData())); - return handleResponse(this, result, ParseApiRQ.executeObjectionFunction, - _debug, parseClassName); + try { + final Response result = await _client.post(uri, + options: Options(headers: headers), + data: json.encode(_getObjectData())); + return handleResponse(this, result, + ParseApiRQ.executeObjectionFunction, _debug, parseClassName); + } on Exception catch (e) { + return handleException( + e, ParseApiRQ.executeObjectionFunction, _debug, parseClassName); + } } } diff --git a/packages/dart/lib/src/objects/response/parse_exception_response.dart b/packages/dart/lib/src/objects/response/parse_exception_response.dart index 89f12e772..c62b452c1 100644 --- a/packages/dart/lib/src/objects/response/parse_exception_response.dart +++ b/packages/dart/lib/src/objects/response/parse_exception_response.dart @@ -3,7 +3,31 @@ part of flutter_parse_sdk; /// Handles exception instead of throwing an exception ParseResponse buildParseResponseWithException(Exception exception) { final ParseResponse response = ParseResponse(); - response.error = - ParseError(message: exception.toString(), exception: exception); + if (exception is DioError) { + try { + Map errorResponse; + + try { + errorResponse = + json.decode(exception.response?.data?.toString() ?? '{}'); + } catch (_) {} + + errorResponse ??= {}; + + response.error = ParseError( + message: errorResponse['error']?.toString() ?? + exception.response?.statusMessage, + exception: exception, + code: errorResponse['code'] ?? exception.response?.statusCode, + ); + } catch (error) { + response.error = ParseError( + message: "Failed to build ParseResponse with exception", + exception: error); + } + } else { + response.error = + ParseError(message: exception.toString(), exception: exception); + } return response; } diff --git a/packages/dart/pubspec.yaml b/packages/dart/pubspec.yaml index 5fff4633e..fc6ec3a3c 100644 --- a/packages/dart/pubspec.yaml +++ b/packages/dart/pubspec.yaml @@ -1,6 +1,6 @@ name: parse_server_sdk description: Dart plugin for Parse Server, (https://parseplatform.org), (https://back4app.com) -version: 2.0.0 +version: 2.0.1 homepage: https://github.com/phillwiggins/flutter_parse_sdk environment: diff --git a/packages/flutter/CHANGELOG.md b/packages/flutter/CHANGELOG.md index c49caff1f..26d9f1a15 100644 --- a/packages/flutter/CHANGELOG.md +++ b/packages/flutter/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.0.1 +Fixed network exceptions. [#482](https://github.com/parse-community/Parse-SDK-Flutter/pull/482) + ## 2.0.0 First release. diff --git a/packages/flutter/README.md b/packages/flutter/README.md index 29bb5f11b..a87e72aee 100644 --- a/packages/flutter/README.md +++ b/packages/flutter/README.md @@ -14,7 +14,7 @@ This is a work in progress and we are consistently updating it. Please let us kn To install, either add to your pubspec.yaml ```yml dependencies: - parse_server_sdk: ^2.0.0 + parse_server_sdk: ^2.0.1 ``` or clone this repository and add to your project. As this is an early development with multiple contributors, it is probably best to download/clone and keep updating as an when a new feature is added. diff --git a/packages/flutter/pubspec.yaml b/packages/flutter/pubspec.yaml index 966c814e6..2c8389d19 100644 --- a/packages/flutter/pubspec.yaml +++ b/packages/flutter/pubspec.yaml @@ -1,6 +1,6 @@ name: parse_server_sdk_flutter description: Flutter plugin for Parse Server, (https://parseplatform.org), (https://back4app.com) -version: 2.0.0 +version: 2.0.1 homepage: https://github.com/phillwiggins/flutter_parse_sdk environment: @@ -10,7 +10,7 @@ dependencies: flutter: sdk: flutter - parse_server_sdk: ^2.0.0 + parse_server_sdk: ^2.0.1 # Networking dio: ^3.0.10