Skip to content

Commit 0becaf9

Browse files
committed
Add HTTPClientError shortDescription property
This adds a shortDescription property to HTTPClientError which provides a short description of the error without associated values.
1 parent 13e93d4 commit 0becaf9

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

Sources/AsyncHTTPClient/HTTPClient.swift

+70
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,76 @@ public struct HTTPClientError: Error, Equatable, CustomStringConvertible {
949949
return "HTTPClientError.\(String(describing: self.code))"
950950
}
951951

952+
/// Short description of the error that can be used in case a bounded set of error descriptions is expected, e.g. to
953+
/// include in metric labels. The description does not contain associated values.
954+
public var shortDescription: String {
955+
// When adding new cases here, do *not* include dynamic (associated) values in the description.
956+
switch self.code {
957+
case .invalidURL:
958+
return "Invalid URL"
959+
case .emptyHost:
960+
return "Empty host"
961+
case .missingSocketPath:
962+
return "Missing socket path"
963+
case .alreadyShutdown:
964+
return "Already shutdown"
965+
case .emptyScheme:
966+
return "Empty scheme"
967+
case .unsupportedScheme:
968+
return "Unsupported scheme"
969+
case .readTimeout:
970+
return "Read timeout"
971+
case .remoteConnectionClosed:
972+
return "Remote connection closed"
973+
case .cancelled:
974+
return "Cancelled"
975+
case .identityCodingIncorrectlyPresent:
976+
return "Identity coding incorrectly present"
977+
case .chunkedSpecifiedMultipleTimes:
978+
return "Chunked specified multiple times"
979+
case .invalidProxyResponse:
980+
return "Invalid proxy response"
981+
case .contentLengthMissing:
982+
return "Content length missing"
983+
case .proxyAuthenticationRequired:
984+
return "Proxy authentication required"
985+
case .redirectLimitReached:
986+
return "Redirect limit reached"
987+
case .redirectCycleDetected:
988+
return "Redirect cycle detected"
989+
case .uncleanShutdown:
990+
return "Unclean shutdown"
991+
case .traceRequestWithBody:
992+
return "Trace request with body"
993+
case .invalidHeaderFieldNames:
994+
return "Invalid header field names"
995+
case .bodyLengthMismatch:
996+
return "Body length mismatch"
997+
case .writeAfterRequestSent:
998+
return "Write after request sent"
999+
case .incompatibleHeaders:
1000+
return "Incompatible headers"
1001+
case .connectTimeout:
1002+
return "Connect timeout"
1003+
case .socksHandshakeTimeout:
1004+
return "SOCKS handshake timeout"
1005+
case .httpProxyHandshakeTimeout:
1006+
return "HTTP proxy handshake timeout"
1007+
case .tlsHandshakeTimeout:
1008+
return "TLS handshake timeout"
1009+
case .serverOfferedUnsupportedApplicationProtocol:
1010+
return "Server offered unsupported application protocol"
1011+
case .requestStreamCancelled:
1012+
return "Request stream cancelled"
1013+
case .getConnectionFromPoolTimeout:
1014+
return "Get connection from pool timeout"
1015+
case .deadlineExceeded:
1016+
return "Deadline exceeded"
1017+
case .httpEndReceivedAfterHeadWith1xx:
1018+
return "HTTP end received after head with 1xx"
1019+
}
1020+
}
1021+
9521022
/// URL provided is invalid.
9531023
public static let invalidURL = HTTPClientError(code: .invalidURL)
9541024
/// URL does not contain host.

0 commit comments

Comments
 (0)