79119283

Date: 2024-10-23 18:44:11
Score: 2.5
Natty:
Report link

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
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @CraigSiemens
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Ryan H