Skip to content

Commit

Permalink
Add an unknown error case to return if we can't generate a WFError
Browse files Browse the repository at this point in the history
  • Loading branch information
AngeloStavrow committed Oct 6, 2020
1 parent 52ea441 commit a671f83
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Sources/WriteFreely/WFClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -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
}
}
}
1 change: 1 addition & 0 deletions Sources/WriteFreely/WFError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum WFError: Int, Error {
case internalServerError = 500
case badGateway = 502
case serviceUnavailable = 503
case unknownError = -1
}

struct ErrorMessage: Codable {
Expand Down

0 comments on commit a671f83

Please sign in to comment.