From 7d04894860a6b1939bbe55a81d2bbbcbac5f5b89 Mon Sep 17 00:00:00 2001 From: Travis Sheppard Date: Fri, 21 May 2021 10:33:25 -0700 Subject: [PATCH 1/7] add httpStatusCode property to APIError and serialize from iOS --- packages/amplify_api/example/lib/main.dart | 5 ++++- packages/amplify_api/example/pubspec.yaml | 2 ++ .../ios/Classes/FlutterApiErrorHandler.swift | 10 +++++++++- .../ios/Classes/FlutterApiResponse.swift | 2 +- .../lib/src/exceptions/ApiException.dart | 18 ++++++++++++------ .../ios/Classes/Support/ErrorUtil.swift | 4 +++- 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/packages/amplify_api/example/lib/main.dart b/packages/amplify_api/example/lib/main.dart index 0bff4a66ce..9d60b3a197 100644 --- a/packages/amplify_api/example/lib/main.dart +++ b/packages/amplify_api/example/lib/main.dart @@ -16,6 +16,7 @@ import 'package:amplify_api/amplify_api.dart'; import 'package:amplify_api_example/graphql_api_view.dart'; import 'package:amplify_api_example/rest_api_view.dart'; +import 'package:amplify_auth_cognito/amplify_auth_cognito.dart'; import 'package:amplify_flutter/amplify.dart'; import 'package:flutter/material.dart'; import 'amplifyconfiguration.dart'; @@ -34,6 +35,7 @@ class _MyAppState extends State { bool _showRestApiView = true; AmplifyAPI apiRest; + AmplifyAuthCognito auth; @override void initState() { @@ -43,8 +45,9 @@ class _MyAppState extends State { void _configureAmplify() async { apiRest = AmplifyAPI(); + auth = AmplifyAuthCognito(); - Amplify.addPlugin(apiRest); + Amplify.addPlugins([auth, apiRest]); try { await Amplify.configure(amplifyconfig); } on AmplifyAlreadyConfiguredException { diff --git a/packages/amplify_api/example/pubspec.yaml b/packages/amplify_api/example/pubspec.yaml index 00a46e948f..14e215a11b 100644 --- a/packages/amplify_api/example/pubspec.yaml +++ b/packages/amplify_api/example/pubspec.yaml @@ -21,6 +21,8 @@ dependencies: path: ../ amplify_flutter: path: ../../amplify_flutter + amplify_auth_cognito: + path: ../../amplify_auth_cognito # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. diff --git a/packages/amplify_api/ios/Classes/FlutterApiErrorHandler.swift b/packages/amplify_api/ios/Classes/FlutterApiErrorHandler.swift index 2881fb9a10..e7da2dd73b 100644 --- a/packages/amplify_api/ios/Classes/FlutterApiErrorHandler.swift +++ b/packages/amplify_api/ios/Classes/FlutterApiErrorHandler.swift @@ -27,9 +27,17 @@ class FlutterApiErrorHandler { } static func createSerializedError(error: APIError) -> Dictionary { + let httpStatusCode: String? + switch error { + case .httpStatusError(let statusCode, _): + httpStatusCode = String(statusCode) + default: + httpStatusCode = nil + } return ErrorUtil.createSerializedError(message: error.errorDescription, recoverySuggestion: error.recoverySuggestion, - underlyingError: error.underlyingError?.localizedDescription) + underlyingError: error.underlyingError?.localizedDescription, + httpStatusCode: httpStatusCode) } } diff --git a/packages/amplify_api/ios/Classes/FlutterApiResponse.swift b/packages/amplify_api/ios/Classes/FlutterApiResponse.swift index b6eeda575c..4d23dc8df9 100644 --- a/packages/amplify_api/ios/Classes/FlutterApiResponse.swift +++ b/packages/amplify_api/ios/Classes/FlutterApiResponse.swift @@ -43,7 +43,7 @@ class FlutterApiResponse { print("An unknown error occured: \(errorDescription)") ErrorUtil.postErrorToFlutterChannel(result: flutterResult, errorCode: "ApiException", - details: ErrorUtil.createSerializedError(message: errorDescription, recoverySuggestion: recoverySuggestion, underlyingError: nil)) + details: ErrorUtil.createSerializedError(message: errorDescription, recoverySuggestion: recoverySuggestion, underlyingError: nil, httpStatusCode: nil)) } } diff --git a/packages/amplify_api_plugin_interface/lib/src/exceptions/ApiException.dart b/packages/amplify_api_plugin_interface/lib/src/exceptions/ApiException.dart index 541710d9c7..d2bd6d2382 100644 --- a/packages/amplify_api_plugin_interface/lib/src/exceptions/ApiException.dart +++ b/packages/amplify_api_plugin_interface/lib/src/exceptions/ApiException.dart @@ -17,22 +17,28 @@ import 'package:amplify_core/types/exception/AmplifyException.dart'; /// Exception thrown from Api Category class ApiException extends AmplifyException { + /// HTTP status of response, only available if error + final int httpStatusCode; + /// Named constructor - const ApiException(String message, - {String recoverySuggestion, String underlyingException}) - : super(message, + ApiException(String message, + {String recoverySuggestion, String underlyingException, int statusCode}) + : httpStatusCode = statusCode, + super(message, recoverySuggestion: recoverySuggestion, underlyingException: underlyingException); /// Constructor for down casting an AmplifyException to this exception - ApiException._private(AmplifyException exception) - : super(exception.message, + ApiException._private(AmplifyException exception, int httpStatusCodeFromException) + : httpStatusCode = httpStatusCodeFromException, + super(exception.message, recoverySuggestion: exception.recoverySuggestion, underlyingException: exception.underlyingException); /// Instantiates and return a new `ApiException` from the /// serialized exception data static ApiException fromMap(Map serializedException) { - return ApiException._private(AmplifyException.fromMap(serializedException)); + final statusCode = int.tryParse(serializedException["httpStatusCode"] ?? "") ?? null; + return ApiException._private(AmplifyException.fromMap(serializedException), statusCode); } } diff --git a/packages/amplify_core/ios/Classes/Support/ErrorUtil.swift b/packages/amplify_core/ios/Classes/Support/ErrorUtil.swift index 177c284588..87dc2652a1 100644 --- a/packages/amplify_core/ios/Classes/Support/ErrorUtil.swift +++ b/packages/amplify_core/ios/Classes/Support/ErrorUtil.swift @@ -26,11 +26,13 @@ public class ErrorUtil { public static func createSerializedError(message: String, recoverySuggestion: String?, - underlyingError: String?) -> Dictionary { + underlyingError: String?, + httpStatusCode: String?) -> Dictionary { var serializedException: Dictionary = [:] serializedException["message"] = message serializedException["recoverySuggestion"] = recoverySuggestion serializedException["underlyingException"] = underlyingError + serializedException["httpStatusCode"] = httpStatusCode return serializedException } } From 975c88d1b5129bcc1b49b00fbf2cbfb64174b9c9 Mon Sep 17 00:00:00 2001 From: Travis Sheppard Date: Fri, 21 May 2021 13:45:51 -0700 Subject: [PATCH 2/7] add httpStatusCode to serialized API error from android --- .../amplify/amplify_api/rest_api/FlutterRestApi.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/amplify_api/android/src/main/kotlin/com/amazonaws/amplify/amplify_api/rest_api/FlutterRestApi.kt b/packages/amplify_api/android/src/main/kotlin/com/amazonaws/amplify/amplify_api/rest_api/FlutterRestApi.kt index 345eb470c6..b3e3489455 100644 --- a/packages/amplify_api/android/src/main/kotlin/com/amazonaws/amplify/amplify_api/rest_api/FlutterRestApi.kt +++ b/packages/amplify_api/android/src/main/kotlin/com/amazonaws/amplify/amplify_api/rest_api/FlutterRestApi.kt @@ -123,13 +123,14 @@ class FlutterRestApi { */ if (!result.code.isSuccessful) { handler.post { - ExceptionUtil.postExceptionToFlutterChannel(flutterResult, "ApiException", - ExceptionUtil.createSerializedError( - ApiException( - "The HTTP response status code is [" + result.code.toString().substring(16, 19) + "].", - recoverySuggestion) - ) + var serializedError = ExceptionUtil.createSerializedError( + ApiException( + "The HTTP response status code is [" + result.code.toString().substring(16, 19) + "].", + recoverySuggestion) ) + var httpStatusCode = result.code?.hashCode()?.toString(); + var serializedErrorWithStatusCode = mapOf("httpStatusCode" to httpStatusCode) + serializedError; + ExceptionUtil.postExceptionToFlutterChannel(flutterResult, "ApiException", serializedErrorWithStatusCode) } return } else { From a4b8a3810c800490595e77fb10ce257fe1028288 Mon Sep 17 00:00:00 2001 From: Travis Sheppard Date: Fri, 21 May 2021 13:57:55 -0700 Subject: [PATCH 3/7] format a file --- .../amplify/amplify_api/rest_api/FlutterRestApi.kt | 9 ++------- .../project.xcworkspace/contents.xcworkspacedata | 2 +- packages/amplify_api/lib/method_channel_api.dart | 11 ++++++++--- .../lib/src/exceptions/ApiException.dart | 9 ++++++--- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/amplify_api/android/src/main/kotlin/com/amazonaws/amplify/amplify_api/rest_api/FlutterRestApi.kt b/packages/amplify_api/android/src/main/kotlin/com/amazonaws/amplify/amplify_api/rest_api/FlutterRestApi.kt index b3e3489455..9cc919c877 100644 --- a/packages/amplify_api/android/src/main/kotlin/com/amazonaws/amplify/amplify_api/rest_api/FlutterRestApi.kt +++ b/packages/amplify_api/android/src/main/kotlin/com/amazonaws/amplify/amplify_api/rest_api/FlutterRestApi.kt @@ -116,19 +116,14 @@ class FlutterRestApi { """ // if code is not 200 then throw an exception - /* - result.code.toString = "Code{" + - "statusCode=" + statusCode + - '}'; - */ if (!result.code.isSuccessful) { handler.post { + var httpStatusCode = result.code?.hashCode()?.toString(); var serializedError = ExceptionUtil.createSerializedError( ApiException( - "The HTTP response status code is [" + result.code.toString().substring(16, 19) + "].", + "The HTTP response status code is [$httpStatusCode].", recoverySuggestion) ) - var httpStatusCode = result.code?.hashCode()?.toString(); var serializedErrorWithStatusCode = mapOf("httpStatusCode" to httpStatusCode) + serializedError; ExceptionUtil.postExceptionToFlutterChannel(flutterResult, "ApiException", serializedErrorWithStatusCode) } diff --git a/packages/amplify_api/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/packages/amplify_api/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata index 1d526a16ed..919434a625 100644 --- a/packages/amplify_api/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/packages/amplify_api/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:"> diff --git a/packages/amplify_api/lib/method_channel_api.dart b/packages/amplify_api/lib/method_channel_api.dart index 745468af0d..5f725cc026 100644 --- a/packages/amplify_api/lib/method_channel_api.dart +++ b/packages/amplify_api/lib/method_channel_api.dart @@ -37,10 +37,10 @@ class AmplifyAPIMethodChannel extends AmplifyAPI { if (e.code == "AmplifyAlreadyConfiguredException") { throw AmplifyAlreadyConfiguredException( AmplifyExceptionMessages.alreadyConfiguredDefaultMessage, - recoverySuggestion: AmplifyExceptionMessages.alreadyConfiguredDefaultSuggestion); + recoverySuggestion: + AmplifyExceptionMessages.alreadyConfiguredDefaultSuggestion); } else { - throw AmplifyException.fromMap( - Map.from(e.details)); + throw AmplifyException.fromMap(Map.from(e.details)); } } } @@ -271,6 +271,11 @@ class AmplifyAPIMethodChannel extends AmplifyAPI { // ====== GENERAL METHODS ====== ApiException _deserializeException(PlatformException e) { + // TEMP question: Would it also be possible/desirable to define more specific error + // exception classes here? For example, could we define HTTPNotFoundError (extends ApiError) + // and look at the serialized httpStatusCode to define which one to create. + // That way, customers would not need `code == 404` etc... + if (e.code == 'ApiException') { return ApiException.fromMap(Map.from(e.details)); } else { diff --git a/packages/amplify_api_plugin_interface/lib/src/exceptions/ApiException.dart b/packages/amplify_api_plugin_interface/lib/src/exceptions/ApiException.dart index d2bd6d2382..1a277220d9 100644 --- a/packages/amplify_api_plugin_interface/lib/src/exceptions/ApiException.dart +++ b/packages/amplify_api_plugin_interface/lib/src/exceptions/ApiException.dart @@ -29,7 +29,8 @@ class ApiException extends AmplifyException { underlyingException: underlyingException); /// Constructor for down casting an AmplifyException to this exception - ApiException._private(AmplifyException exception, int httpStatusCodeFromException) + ApiException._private( + AmplifyException exception, int httpStatusCodeFromException) : httpStatusCode = httpStatusCodeFromException, super(exception.message, recoverySuggestion: exception.recoverySuggestion, @@ -38,7 +39,9 @@ class ApiException extends AmplifyException { /// Instantiates and return a new `ApiException` from the /// serialized exception data static ApiException fromMap(Map serializedException) { - final statusCode = int.tryParse(serializedException["httpStatusCode"] ?? "") ?? null; - return ApiException._private(AmplifyException.fromMap(serializedException), statusCode); + final statusCode = + int.tryParse(serializedException["httpStatusCode"] ?? "") ?? null; + return ApiException._private( + AmplifyException.fromMap(serializedException), statusCode); } } From 5a6e785add289052f725e207fdfa9a85cb51d7fc Mon Sep 17 00:00:00 2001 From: Travis Sheppard Date: Tue, 25 May 2021 14:34:04 -0700 Subject: [PATCH 4/7] remove example app changes --- .../project.xcworkspace/contents.xcworkspacedata | 2 +- packages/amplify_api/example/lib/main.dart | 5 +---- packages/amplify_api/example/pubspec.yaml | 2 -- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/amplify_api/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/packages/amplify_api/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata index 919434a625..1d526a16ed 100644 --- a/packages/amplify_api/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/packages/amplify_api/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "group:Runner.xcodeproj"> diff --git a/packages/amplify_api/example/lib/main.dart b/packages/amplify_api/example/lib/main.dart index 9d60b3a197..0bff4a66ce 100644 --- a/packages/amplify_api/example/lib/main.dart +++ b/packages/amplify_api/example/lib/main.dart @@ -16,7 +16,6 @@ import 'package:amplify_api/amplify_api.dart'; import 'package:amplify_api_example/graphql_api_view.dart'; import 'package:amplify_api_example/rest_api_view.dart'; -import 'package:amplify_auth_cognito/amplify_auth_cognito.dart'; import 'package:amplify_flutter/amplify.dart'; import 'package:flutter/material.dart'; import 'amplifyconfiguration.dart'; @@ -35,7 +34,6 @@ class _MyAppState extends State { bool _showRestApiView = true; AmplifyAPI apiRest; - AmplifyAuthCognito auth; @override void initState() { @@ -45,9 +43,8 @@ class _MyAppState extends State { void _configureAmplify() async { apiRest = AmplifyAPI(); - auth = AmplifyAuthCognito(); - Amplify.addPlugins([auth, apiRest]); + Amplify.addPlugin(apiRest); try { await Amplify.configure(amplifyconfig); } on AmplifyAlreadyConfiguredException { diff --git a/packages/amplify_api/example/pubspec.yaml b/packages/amplify_api/example/pubspec.yaml index 14e215a11b..00a46e948f 100644 --- a/packages/amplify_api/example/pubspec.yaml +++ b/packages/amplify_api/example/pubspec.yaml @@ -21,8 +21,6 @@ dependencies: path: ../ amplify_flutter: path: ../../amplify_flutter - amplify_auth_cognito: - path: ../../amplify_auth_cognito # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. From 371173fa0bd15c4dc67d3917b663c4d1495d5fc9 Mon Sep 17 00:00:00 2001 From: Travis Sheppard Date: Tue, 25 May 2021 15:00:13 -0700 Subject: [PATCH 5/7] fix android unit test for serializing status code error --- .../com/amazonaws/amplify/amplify_api/AmplifyApiRestTest.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/amplify_api/android/src/test/kotlin/com/amazonaws/amplify/amplify_api/AmplifyApiRestTest.kt b/packages/amplify_api/android/src/test/kotlin/com/amazonaws/amplify/amplify_api/AmplifyApiRestTest.kt index f286d63db0..8468397072 100644 --- a/packages/amplify_api/android/src/test/kotlin/com/amazonaws/amplify/amplify_api/AmplifyApiRestTest.kt +++ b/packages/amplify_api/android/src/test/kotlin/com/amazonaws/amplify/amplify_api/AmplifyApiRestTest.kt @@ -297,7 +297,8 @@ class AmplifyApiRestTest { For more information on HTTP status codes, take a look at https://en.wikipedia.org/wiki/List_of_HTTP_status_codes """, - "message" to "The HTTP response status code is [400]." + "message" to "The HTTP response status code is [400].", + "httpStatusCode" to "400" ) ) From bea53c353b890c17367077394f68378a8c28bf90 Mon Sep 17 00:00:00 2001 From: Travis Sheppard Date: Tue, 25 May 2021 15:23:45 -0700 Subject: [PATCH 6/7] some tests --- .../amplify_api/rest_api/FlutterRestApi.kt | 4 +- .../ios/unit_tests/RestApiUnitTests.swift | 1 + .../test/amplify_rest_api_methods_test.dart | 72 +++++++++++++++++++ .../lib/src/exceptions/ApiException.dart | 6 +- 4 files changed, 80 insertions(+), 3 deletions(-) diff --git a/packages/amplify_api/android/src/main/kotlin/com/amazonaws/amplify/amplify_api/rest_api/FlutterRestApi.kt b/packages/amplify_api/android/src/main/kotlin/com/amazonaws/amplify/amplify_api/rest_api/FlutterRestApi.kt index 9cc919c877..df680e2aba 100644 --- a/packages/amplify_api/android/src/main/kotlin/com/amazonaws/amplify/amplify_api/rest_api/FlutterRestApi.kt +++ b/packages/amplify_api/android/src/main/kotlin/com/amazonaws/amplify/amplify_api/rest_api/FlutterRestApi.kt @@ -118,13 +118,13 @@ class FlutterRestApi { // if code is not 200 then throw an exception if (!result.code.isSuccessful) { handler.post { - var httpStatusCode = result.code?.hashCode()?.toString(); + var httpStatusCode = result.code?.hashCode()?.toString() var serializedError = ExceptionUtil.createSerializedError( ApiException( "The HTTP response status code is [$httpStatusCode].", recoverySuggestion) ) - var serializedErrorWithStatusCode = mapOf("httpStatusCode" to httpStatusCode) + serializedError; + var serializedErrorWithStatusCode = mapOf("httpStatusCode" to httpStatusCode) + serializedError ExceptionUtil.postExceptionToFlutterChannel(flutterResult, "ApiException", serializedErrorWithStatusCode) } return diff --git a/packages/amplify_api/example/ios/unit_tests/RestApiUnitTests.swift b/packages/amplify_api/example/ios/unit_tests/RestApiUnitTests.swift index ddee637a70..ad0078fb7c 100644 --- a/packages/amplify_api/example/ios/unit_tests/RestApiUnitTests.swift +++ b/packages/amplify_api/example/ios/unit_tests/RestApiUnitTests.swift @@ -174,6 +174,7 @@ class RestApiUnitTests: XCTestCase { XCTAssertEqual(referenceError.errorDescription, errorMap["message"]) XCTAssertEqual(referenceError.recoverySuggestion, errorMap["recoverySuggestion"]) + XCTAssertEqual("400", errorMap["httpStatusCode"]) } ) } diff --git a/packages/amplify_api/test/amplify_rest_api_methods_test.dart b/packages/amplify_api/test/amplify_rest_api_methods_test.dart index a823d638a5..2b2866c56b 100644 --- a/packages/amplify_api/test/amplify_rest_api_methods_test.dart +++ b/packages/amplify_api/test/amplify_rest_api_methods_test.dart @@ -171,6 +171,78 @@ void main() { } }); + test('GET exception adds the httpStatusCode to exception if available', + () async { + apiChannel.setMockMethodCallHandler((MethodCall methodCall) async { + if (methodCall.method == "get") { + throw PlatformException(code: 'ApiException', details: { + 'message': 'AMPLIFY_API_MUTATE_FAILED', + 'recoverySuggestion': 'some insightful suggestion', + 'underlyingException': 'Act of God', + 'httpStatusCode': '500' + }); + } + }); + + try { + RestOperation restOperation = api.get( + restOptions: RestOptions( + path: "/items", + )); + await restOperation.response; + } on ApiException catch (e) { + expect(e.httpStatusCode, 500); + } + }); + + test('GET exception does not add httpStatusCode if not a valid status code', + () async { + apiChannel.setMockMethodCallHandler((MethodCall methodCall) async { + if (methodCall.method == "get") { + throw PlatformException(code: 'ApiException', details: { + 'message': 'AMPLIFY_API_MUTATE_FAILED', + 'recoverySuggestion': 'some insightful suggestion', + 'underlyingException': 'Act of God', + 'httpStatusCode': '999' + }); + } + }); + + try { + RestOperation restOperation = api.get( + restOptions: RestOptions( + path: "/items", + )); + await restOperation.response; + } on ApiException catch (e) { + expect(e.httpStatusCode, null); + } + }); + + test( + 'GET exception does not add httpStatusCode if not available in serialized error', + () async { + apiChannel.setMockMethodCallHandler((MethodCall methodCall) async { + if (methodCall.method == "get") { + throw PlatformException(code: 'ApiException', details: { + 'message': 'AMPLIFY_API_MUTATE_FAILED', + 'recoverySuggestion': 'some insightful suggestion', + 'underlyingException': 'Act of God', + }); + } + }); + + try { + RestOperation restOperation = api.get( + restOptions: RestOptions( + path: "/items", + )); + await restOperation.response; + } on ApiException catch (e) { + expect(e.httpStatusCode, null); + } + }); + test('CANCEL success does not throw error', () async { // Need to reply with PLACEHOLDER to avoid null issues in _formatRestResponse // In actual production code, the methodChannel doesn't respond to the future response diff --git a/packages/amplify_api_plugin_interface/lib/src/exceptions/ApiException.dart b/packages/amplify_api_plugin_interface/lib/src/exceptions/ApiException.dart index 1a277220d9..5fb754ff08 100644 --- a/packages/amplify_api_plugin_interface/lib/src/exceptions/ApiException.dart +++ b/packages/amplify_api_plugin_interface/lib/src/exceptions/ApiException.dart @@ -39,8 +39,12 @@ class ApiException extends AmplifyException { /// Instantiates and return a new `ApiException` from the /// serialized exception data static ApiException fromMap(Map serializedException) { - final statusCode = + var statusCode = int.tryParse(serializedException["httpStatusCode"] ?? "") ?? null; + // Ensure a valid HTTP status code for an error. + if (statusCode != null && (statusCode < 300 || statusCode > 511)) { + statusCode = null; + } return ApiException._private( AmplifyException.fromMap(serializedException), statusCode); } From 5f5a8f402412d94ebe407635161c68b0258847f4 Mon Sep 17 00:00:00 2001 From: Travis Sheppard Date: Tue, 8 Jun 2021 10:43:38 -0700 Subject: [PATCH 7/7] remove open question comment --- packages/amplify_api/lib/method_channel_api.dart | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/packages/amplify_api/lib/method_channel_api.dart b/packages/amplify_api/lib/method_channel_api.dart index 5f725cc026..745468af0d 100644 --- a/packages/amplify_api/lib/method_channel_api.dart +++ b/packages/amplify_api/lib/method_channel_api.dart @@ -37,10 +37,10 @@ class AmplifyAPIMethodChannel extends AmplifyAPI { if (e.code == "AmplifyAlreadyConfiguredException") { throw AmplifyAlreadyConfiguredException( AmplifyExceptionMessages.alreadyConfiguredDefaultMessage, - recoverySuggestion: - AmplifyExceptionMessages.alreadyConfiguredDefaultSuggestion); + recoverySuggestion: AmplifyExceptionMessages.alreadyConfiguredDefaultSuggestion); } else { - throw AmplifyException.fromMap(Map.from(e.details)); + throw AmplifyException.fromMap( + Map.from(e.details)); } } } @@ -271,11 +271,6 @@ class AmplifyAPIMethodChannel extends AmplifyAPI { // ====== GENERAL METHODS ====== ApiException _deserializeException(PlatformException e) { - // TEMP question: Would it also be possible/desirable to define more specific error - // exception classes here? For example, could we define HTTPNotFoundError (extends ApiError) - // and look at the serialized httpStatusCode to define which one to create. - // That way, customers would not need `code == 404` etc... - if (e.code == 'ApiException') { return ApiException.fromMap(Map.from(e.details)); } else {