Improved the "getAmiibos(by: )" function for the AmiiboLiveClient client in the package target.
This commit is contained in:
parent
4a8f402036
commit
420ed8f7a3
@ -11,6 +11,7 @@
|
||||
//===----------------------------------------------------------------------===
|
||||
|
||||
import Foundation
|
||||
import OpenAPIRuntime
|
||||
import OpenAPIURLSession
|
||||
|
||||
public struct AmiiboLiveClient {
|
||||
@ -38,19 +39,31 @@ extension AmiiboLiveClient: APIClient {
|
||||
// MARK: Functions
|
||||
|
||||
public func getAmiibos(by filter: AmiiboFilter) async throws -> [Amiibo] {
|
||||
let response = try await client.getAmiibos(
|
||||
.init(query: .init(
|
||||
amiiboSeries: filter.series,
|
||||
character: filter.gameCharacter,
|
||||
gameseries: filter.gameSeries,
|
||||
id: filter.identifier,
|
||||
name: filter.name,
|
||||
showgames: filter.showGames,
|
||||
showusage: filter.showUsage,
|
||||
_type: filter.type
|
||||
))
|
||||
)
|
||||
|
||||
let response = try await {
|
||||
do {
|
||||
return try await client.getAmiibos(
|
||||
.init(query: .init(
|
||||
amiiboSeries: filter.series,
|
||||
character: filter.gameCharacter,
|
||||
gameseries: filter.gameSeries,
|
||||
id: filter.identifier,
|
||||
name: filter.name,
|
||||
showgames: filter.showGames,
|
||||
showusage: filter.showUsage,
|
||||
_type: filter.type
|
||||
))
|
||||
)
|
||||
} catch let error as ClientError {
|
||||
guard let _ = error.underlyingError as? DecodingError else {
|
||||
throw AmiiboServiceError.unknown
|
||||
}
|
||||
|
||||
throw AmiiboServiceError.decoding
|
||||
} catch {
|
||||
throw AmiiboServiceError.unknown
|
||||
}
|
||||
}()
|
||||
|
||||
switch response {
|
||||
case let .ok(ok):
|
||||
switch ok.body {
|
||||
|
@ -12,9 +12,11 @@
|
||||
|
||||
public enum AmiiboServiceError: Error {
|
||||
case badRequest
|
||||
case decoding
|
||||
case notAvailable
|
||||
case notFound
|
||||
case undocumented(_ statusCode: Int)
|
||||
case unknown
|
||||
}
|
||||
|
||||
// MARK: - Equatable
|
||||
|
@ -67,7 +67,7 @@ struct AmiiboServiceLiveTests {
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: AmiiboServiceError.undocumented(404)) {
|
||||
await #expect(throws: AmiiboServiceError.decoding) {
|
||||
try await service.getAmiibos(.init(identifier: identifier))
|
||||
}
|
||||
}
|
||||
@ -79,7 +79,7 @@ struct AmiiboServiceLiveTests {
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: AmiiboServiceError.undocumented(404)) {
|
||||
await #expect(throws: AmiiboServiceError.decoding) {
|
||||
try await service.getAmiibos(.init(identifier: identifier))
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user