Thanks to the post reference by @CraigSiemens, I was able to get this to work by modifying my error extension as per the post within the referenced post by @Abuzeid.
extension APIError: LocalizedError {
public var description: String {
switch self {
case .invalidPath:
return "Invalid Path"
case .decodingError:
return "There was an error decoding the response"
case .invalidServerResponse:
return "Network request error."
case .resourceUnavailable(let error):
return "Server or resource not available. Status Code: \(error)"
}
}
public var errorDescription: String? {
return description
}
}
I then updated my print statement to this;
print(error.localizedDescription.description)
And now I get an output I want like below;
Server or resource not available. Status Code:404