diff --git a/Sources/AmiiboService/Public/Clients/AmiiboLiveClient.swift b/Sources/AmiiboService/Public/Clients/AmiiboLiveClient.swift index ecac350..79e167d 100644 --- a/Sources/AmiiboService/Public/Clients/AmiiboLiveClient.swift +++ b/Sources/AmiiboService/Public/Clients/AmiiboLiveClient.swift @@ -372,21 +372,28 @@ private extension AmiiboLiveClient { throw AmiiboServiceError.decoding case let urlError as URLError: switch urlError.code { + case .cancelled: + throw AmiiboServiceError.cancelled + case .cannotParseResponse: + throw AmiiboServiceError.decoding case .cannotFindHost, .cannotConnectToHost, + .dataNotAllowed, .dnsLookupFailed, + .internationalRoamingOff, .networkConnectionLost, .notConnectedToInternet, + .secureConnectionFailed, .timedOut: throw AmiiboServiceError.notAvailable default: - throw AmiiboServiceError.unknown + throw AmiiboServiceError.unknown(String(describing: urlError)) } default: - throw AmiiboServiceError.unknown + throw AmiiboServiceError.unknown(String(describing: clientError.underlyingError)) } default: - throw AmiiboServiceError.unknown + throw AmiiboServiceError.unknown(String(describing: error)) } } diff --git a/Sources/AmiiboService/Public/Errors/AmiiboServiceError.swift b/Sources/AmiiboService/Public/Errors/AmiiboServiceError.swift index aa0e432..e2817d9 100644 --- a/Sources/AmiiboService/Public/Errors/AmiiboServiceError.swift +++ b/Sources/AmiiboService/Public/Errors/AmiiboServiceError.swift @@ -28,8 +28,8 @@ public enum AmiiboServiceError: Error { case notFound /// The server returned an undocumented HTTP status code. case undocumented(_ statusCode: Int) - /// An unexpected error that does not fall into any other category. - case unknown + /// An unexpected error that does not fall into any other category, with a description of the underlying error. + case unknown(_ description: String) } // MARK: - Equatable @@ -50,7 +50,7 @@ extension AmiiboServiceError: LocalizedError { case .notAvailable: "The backend service is currently unreachable due to a network or server issue." case .notFound: "No results were found matching the given filter criteria." case .undocumented(let statusCode): "The server returned an undocumented HTTP status code: \(statusCode)." - case .unknown: "An unexpected error occurred." + case .unknown(let description): "An unexpected error occurred: \(description)" } } diff --git a/Tests/AmiiboService/Cases/Public/Services/AmiiboServiceMockTests.swift b/Tests/AmiiboService/Cases/Public/Services/AmiiboServiceMockTests.swift index df8a219..3cdf2f7 100644 --- a/Tests/AmiiboService/Cases/Public/Services/AmiiboServiceMockTests.swift +++ b/Tests/AmiiboService/Cases/Public/Services/AmiiboServiceMockTests.swift @@ -261,6 +261,6 @@ private enum Errors { .notAvailable, .notFound, .undocumented(500), - .unknown + .unknown("An underlying error description.") ] }