Skip to content

Add HTTPClientError shortDescription property #583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions Sources/AsyncHTTPClient/HTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,76 @@ public struct HTTPClientError: Error, Equatable, CustomStringConvertible {
return "HTTPClientError.\(String(describing: self.code))"
}

/// Short description of the error that can be used in case a bounded set of error descriptions is expected, e.g. to
/// include in metric labels. For this reason the description must not contain associated values.
public var shortDescription: String {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a comment that describes, when users should use shortDescription and what they need to take into consideration when adding another case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added now. Happy to adjust the comments of course!

// When adding new cases here, do *not* include dynamic (associated) values in the description.
switch self.code {
case .invalidURL:
return "Invalid URL"
case .emptyHost:
return "Empty host"
case .missingSocketPath:
return "Missing socket path"
case .alreadyShutdown:
return "Already shutdown"
case .emptyScheme:
return "Empty scheme"
case .unsupportedScheme:
return "Unsupported scheme"
case .readTimeout:
return "Read timeout"
case .remoteConnectionClosed:
return "Remote connection closed"
case .cancelled:
return "Cancelled"
case .identityCodingIncorrectlyPresent:
return "Identity coding incorrectly present"
case .chunkedSpecifiedMultipleTimes:
return "Chunked specified multiple times"
case .invalidProxyResponse:
return "Invalid proxy response"
case .contentLengthMissing:
return "Content length missing"
case .proxyAuthenticationRequired:
return "Proxy authentication required"
case .redirectLimitReached:
return "Redirect limit reached"
case .redirectCycleDetected:
return "Redirect cycle detected"
case .uncleanShutdown:
return "Unclean shutdown"
case .traceRequestWithBody:
return "Trace request with body"
case .invalidHeaderFieldNames:
return "Invalid header field names"
case .bodyLengthMismatch:
return "Body length mismatch"
case .writeAfterRequestSent:
return "Write after request sent"
case .incompatibleHeaders:
return "Incompatible headers"
case .connectTimeout:
return "Connect timeout"
case .socksHandshakeTimeout:
return "SOCKS handshake timeout"
case .httpProxyHandshakeTimeout:
return "HTTP proxy handshake timeout"
case .tlsHandshakeTimeout:
return "TLS handshake timeout"
case .serverOfferedUnsupportedApplicationProtocol:
return "Server offered unsupported application protocol"
case .requestStreamCancelled:
return "Request stream cancelled"
case .getConnectionFromPoolTimeout:
return "Get connection from pool timeout"
case .deadlineExceeded:
return "Deadline exceeded"
case .httpEndReceivedAfterHeadWith1xx:
return "HTTP end received after head with 1xx"
}
}

/// URL provided is invalid.
public static let invalidURL = HTTPClientError(code: .invalidURL)
/// URL does not contain host.
Expand Down