From a671f83d3785b43cb09283c6ba5e3d9fd7183b9c Mon Sep 17 00:00:00 2001 From: Angelo Stavrow Date: Tue, 6 Oct 2020 16:01:05 -0400 Subject: [PATCH] Add an unknown error case to return if we can't generate a WFError --- Sources/WriteFreely/WFClient.swift | 9 +++++++-- Sources/WriteFreely/WFError.swift | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Sources/WriteFreely/WFClient.swift b/Sources/WriteFreely/WFClient.swift index ced0ed8..cb141e7 100644 --- a/Sources/WriteFreely/WFClient.swift +++ b/Sources/WriteFreely/WFClient.swift @@ -924,7 +924,11 @@ public class WFClient { } } else { // We didn't get a 200 OK, so return a WFError - guard let error = self.translateWFError(fromServerResponse: data) else { return } + guard let error = self.translateWFError(fromServerResponse: data) else { + // We couldn't generate a WFError from the server response data, so return an unknown error. + completion(.failure(WFError.unknownError)) + return + } completion(.failure(error)) } } @@ -1088,7 +1092,8 @@ private extension WFClient { print("⛔️ \(error.message)") return WFError(rawValue: error.code) } catch { - return nil + print("⛔️ An unknown error occurred.") + return WFError.unknownError } } } diff --git a/Sources/WriteFreely/WFError.swift b/Sources/WriteFreely/WFError.swift index fa32912..ce50582 100644 --- a/Sources/WriteFreely/WFError.swift +++ b/Sources/WriteFreely/WFError.swift @@ -12,6 +12,7 @@ public enum WFError: Int, Error { case internalServerError = 500 case badGateway = 502 case serviceUnavailable = 503 + case unknownError = -1 } struct ErrorMessage: Codable {