Created
November 13, 2023 15:49
-
-
Save denpazakura/16a33f2e5f85c7e3ad7366e706e1bbcd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
enum HTTPClientError { | |
case badRequest | |
case unauthorized | |
case paymentRequired | |
case forbidden | |
case notFound | |
case methodNotAllowed | |
case notAcceptable | |
case proxyAuthenticationRequired | |
case requestTimeout | |
case conflict | |
case gone | |
case lengthRequired | |
case preconditionFailed | |
case payloadTooLarge | |
case uriTooLong | |
case unsupportedMediaType | |
case rangeNotSatisfiable | |
case expectationFailed | |
case teapot | |
case pageExpired | |
case methodFailure | |
case misdirectedRequest | |
case unprocessableEntity | |
case locked | |
case failedDependency | |
case tooEarly | |
case upgradeRequired | |
case preconditionRequired | |
case tooManyRequests | |
case httpStatusCode | |
case requestHeaderFieldsTooLarge | |
case loginTimeout | |
case noResponse | |
case retryWith | |
case blockedByWindowsParentalControls | |
case unavailableForLegalReasons | |
case clientClosedConnection | |
case tooManyForwardedIPAddresses | |
case incompatibleProtocol | |
case requestHeaderTooLarge | |
case sslCertificateError | |
case sslCertificateRequired | |
case httpRequestSentToHTTPSPort | |
case invalidToken | |
case tokenRequiredOrClientClosedRequest | |
case unexpected(_ code: Int) | |
} | |
extension HTTPClientError: LocalizedError { | |
public var errorDescription: String? { | |
switch self { | |
case .badRequest: | |
return NSLocalizedString("Check if the URL is correct", comment: "bad request") | |
case .unauthorized: | |
return NSLocalizedString("You are not authorized to view this resource", comment: "unauthorized") | |
case .paymentRequired: | |
return NSLocalizedString("Payment is required before the client can access the requested resource", comment: "payment required") | |
case .forbidden: | |
return NSLocalizedString("You do not have sufficient permissions to access the resource", comment: "access forbidden") | |
case .notFound: | |
return NSLocalizedString("The resource can not be found at the specified address", comment: "resource not found") | |
case .methodNotAllowed: | |
return NSLocalizedString("The resource specified by the request exists but the requested HTTP method is not allowed", comment: "resource not found") | |
case .unexpected(let code): | |
return NSLocalizedString("An unexpected error occurred, code: \(code)", comment: "unexpected error") | |
default: | |
return NSLocalizedString("A client error occurred", comment: "http error") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment