Skip to content

Commit

Permalink
fix: error handling changes in geo and geo test suite (#3256)
Browse files Browse the repository at this point in the history
  • Loading branch information
atierian authored Sep 29, 2023
1 parent 5aacb0b commit 0f6b32c
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,14 @@ extension AWSLocationGeoPlugin {
country: $0.country)
}
return places
} catch let error as GeoErrorConvertible {
throw error.geoError
} catch {
let geoError = GeoErrorHelper.mapAWSLocationError(error)
throw geoError
throw Geo.Error.unknown(
error.localizedDescription,
"See underlying error.",
error
)
}
}

Expand Down Expand Up @@ -167,9 +172,14 @@ extension AWSLocationGeoPlugin {
country: $0.country)
}
return places
} catch let error as GeoErrorConvertible {
throw error.geoError
} catch {
let geoError = GeoErrorHelper.mapAWSLocationError(error)
throw geoError
throw Geo.Error.unknown(
error.localizedDescription,
"See underlying error.",
error
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ extension AWSLocationGeoPlugin {
let authService = AWSAuthService()
let credentialsProvider = authService.getCredentialsProvider()
let region = configuration.regionName
// TODO: FrameworkMetadata Replacement
let serviceConfiguration = try LocationClient.LocationClientConfiguration(
credentialsProvider: credentialsProvider,
frameworkMetadata: AmplifyAWSServiceConfiguration.frameworkMetaData(),
region: region)
region: region,
credentialsProvider: credentialsProvider
)

#if os(iOS) || os(macOS) // no-op
#else
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

import Amplify
import Foundation
import AWSLocation
import AWSClientRuntime

protocol GeoErrorConvertible {
var geoError: Geo.Error { get }
}

extension AWSLocation.AccessDeniedException: GeoErrorConvertible {
var geoError: Geo.Error {
.accessDenied(
message ?? "",
GeoPluginErrorConstants.accessDenied,
self
)
}
}

extension AWSLocation.InternalServerException: GeoErrorConvertible {
var geoError: Geo.Error {
.serviceError(
message ?? "",
GeoPluginErrorConstants.internalServer,
self
)
}
}

extension AWSLocation.ResourceNotFoundException: GeoErrorConvertible {
var geoError: Geo.Error {
.serviceError(
message ?? "",
GeoPluginErrorConstants.resourceNotFound,
self
)
}
}

extension AWSLocation.ThrottlingException: GeoErrorConvertible {
var geoError: Geo.Error {
.serviceError(
message ?? "",
GeoPluginErrorConstants.throttling,
self
)
}
}

extension AWSLocation.ValidationException: GeoErrorConvertible {
var geoError: Geo.Error {
.serviceError(
message ?? "",
GeoPluginErrorConstants.validation,
self
)
}
}

extension AWSClientRuntime.UnknownAWSHTTPServiceError: GeoErrorConvertible {
var geoError: Geo.Error {
.unknown(
"""
Unknown service error occured with:
- status: \(httpResponse.statusCode)
- message: \(message ?? "")
""",
"",
self
)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,56 +14,17 @@ import XCTest
@testable import AWSLocationGeoPlugin
@testable import AWSPluginsTestCommon

class MockAWSClientConfiguration: LocationClientConfigurationProtocol {
var encoder: ClientRuntime.RequestEncoder?

var decoder: ClientRuntime.ResponseDecoder?

var httpClientEngine: ClientRuntime.HttpClientEngine

var httpClientConfiguration: ClientRuntime.HttpClientConfiguration

var idempotencyTokenGenerator: ClientRuntime.IdempotencyTokenGenerator

var clientLogMode: ClientRuntime.ClientLogMode

var partitionID: String?

var useFIPS: Bool?

var useDualStack: Bool?

var endpoint: String?

var credentialsProvider: CredentialsProvider

var region: String?

var signingRegion: String?

var endpointResolver: EndpointResolver

var regionResolver: RegionResolver?

var frameworkMetadata: FrameworkMetadata?

var logger: LogAgent

var retryer: SDKRetryer

init(config: AWSLocationGeoPluginConfiguration) throws {
let defaultSDKRuntimeConfig = try DefaultSDKRuntimeConfiguration("MockAWSClientConfiguration")

self.httpClientEngine = defaultSDKRuntimeConfig.httpClientEngine
self.httpClientConfiguration = defaultSDKRuntimeConfig.httpClientConfiguration
self.idempotencyTokenGenerator = defaultSDKRuntimeConfig.idempotencyTokenGenerator
self.clientLogMode = defaultSDKRuntimeConfig.clientLogMode
self.credentialsProvider = MockAWSAuthService().getCredentialsProvider()
self.region = config.regionName
self.signingRegion = ""
self.endpointResolver = MockEndPointResolver()
self.logger = MockLogAgent()
self.retryer = try SDKRetryer(options: RetryOptions(jitterMode: .default))
extension LocationClient.LocationClientConfiguration {
static func mock(region: String) throws -> LocationClient.LocationClientConfiguration {
try .init(
region: region,
credentialsProvider: MockAWSAuthService().getCredentialsProvider(),
serviceSpecific: .init(
endpointResolver: MockEndPointResolver()
),
signingRegion: "",
retryMode: .standard
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public class MockAWSLocation: AWSLocationBehavior {

public init(pluginConfig: AWSLocationGeoPluginConfiguration) throws {
self.locationClient = try LocationClient(
config: MockAWSClientConfiguration(config: pluginConfig))
config: .mock(region: pluginConfig.regionName)
)
}

public func getEscapeHatch() -> LocationClient {
Expand Down

0 comments on commit 0f6b32c

Please sign in to comment.