Several fixes and optimizations all over the library #28

Merged
javier merged 22 commits from library/several-fixes-and-optimizations into main 2026-07-26 09:56:33 +00:00
3 changed files with 14 additions and 7 deletions
Showing only changes of commit 03f66cdeb3 - Show all commits
@@ -372,21 +372,28 @@ private extension AmiiboLiveClient {
throw AmiiboServiceError.decoding throw AmiiboServiceError.decoding
case let urlError as URLError: case let urlError as URLError:
switch urlError.code { switch urlError.code {
case .cancelled:
throw AmiiboServiceError.cancelled
case .cannotParseResponse:
throw AmiiboServiceError.decoding
case .cannotFindHost, case .cannotFindHost,
.cannotConnectToHost, .cannotConnectToHost,
.dataNotAllowed,
.dnsLookupFailed, .dnsLookupFailed,
.internationalRoamingOff,
.networkConnectionLost, .networkConnectionLost,
.notConnectedToInternet, .notConnectedToInternet,
.secureConnectionFailed,
.timedOut: .timedOut:
throw AmiiboServiceError.notAvailable throw AmiiboServiceError.notAvailable
default: default:
throw AmiiboServiceError.unknown throw AmiiboServiceError.unknown(String(describing: urlError))
} }
default: default:
throw AmiiboServiceError.unknown throw AmiiboServiceError.unknown(String(describing: clientError.underlyingError))
} }
default: default:
throw AmiiboServiceError.unknown throw AmiiboServiceError.unknown(String(describing: error))
} }
} }
@@ -28,8 +28,8 @@ public enum AmiiboServiceError: Error {
case notFound case notFound
/// The server returned an undocumented HTTP status code. /// The server returned an undocumented HTTP status code.
case undocumented(_ statusCode: Int) case undocumented(_ statusCode: Int)
/// An unexpected error that does not fall into any other category. /// An unexpected error that does not fall into any other category, with a description of the underlying error.
case unknown case unknown(_ description: String)
} }
// MARK: - Equatable // 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 .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 .notFound: "No results were found matching the given filter criteria."
case .undocumented(let statusCode): "The server returned an undocumented HTTP status code: \(statusCode)." 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)"
} }
} }
@@ -261,6 +261,6 @@ private enum Errors {
.notAvailable, .notAvailable,
.notFound, .notFound,
.undocumented(500), .undocumented(500),
.unknown .unknown("An underlying error description.")
] ]
} }