Skip to content

Error Types

ClientError

go
type ClientError = engine.ClientError

Classified HTTP client error, extracted via errors.As.

Struct Fields

go
type ClientError struct {
    Type       ErrorType  // Error classification
    Message    string     // Error description
    Cause      error      // Underlying error
    URL        string     // Request URL (masked)
    Method     string     // HTTP method
    Attempts   int        // Number of attempts made
    StatusCode int        // HTTP status code (if applicable)
    Host       string     // Hostname (for circuit breaker use)
}
FieldTypeDescription
TypeErrorTypeError classification for switch statements
MessagestringError description
CauseerrorUnderlying error, accessible via Unwrap()
URLstringRequest URL (credentials masked)
MethodstringHTTP method (GET, POST, etc.)
AttemptsintNumber of attempts (including the first request)
StatusCodeintHTTP status code (0 for non-HTTP errors)
HoststringRequest hostname

Methods

MethodReturnDescription
Error()stringFormatted as METHOD URL: Message: Cause (attempt N)
Code()stringReadable error code, e.g. "NETWORK_ERROR", "TIMEOUT"
IsRetryable()boolWhether the error is retryable
Unwrap()errorUnwraps the underlying error
WithType(t ErrorType)*ClientErrorReturns a copy with the error type set (does not modify original)
go
var clientErr *httpc.ClientError
if errors.As(err, &clientErr) {
    fmt.Println("Error type:", clientErr.Code())
    fmt.Println("Request URL:", clientErr.URL)
    fmt.Println("Retry attempts:", clientErr.Attempts)
    fmt.Println("Retryable:", clientErr.IsRetryable())
    fmt.Println("Underlying error:", clientErr.Unwrap())
}

ErrorType

go
type ErrorType = engine.ErrorType

Error classification enum.

ConstantDescriptionRetryable
ErrorTypeUnknownUnknown/unclassified errorNo
ErrorTypeNetworkNetwork error (connection refused, connection reset, etc.)Conditional
ErrorTypeTimeoutRequest timeoutConditional¹
ErrorTypeContextCanceledContext canceledNo
ErrorTypeResponseReadResponse body read errorConditional
ErrorTypeTransportTransport layer errorYes
ErrorTypeRetryExhaustedRetries exhaustedNo
ErrorTypeTLSTLS errorNo
ErrorTypeCertificateCertificate verification errorNo
ErrorTypeDNSDNS resolution errorConditional
ErrorTypeValidationRequest validation errorNo
ErrorTypeHTTPHTTP layer errorConditional

¹ Timeouts triggered by a context deadline (WithTimeout, TimeoutConfig.Request) are not retried; only transport-level timeouts (e.g. net.OpError timeout) are retried.

Type Checking

go
result, err := client.Get(url)
if err != nil {
    var clientErr *httpc.ClientError
    if errors.As(err, &clientErr) {
        switch clientErr.Type {
        case httpc.ErrorTypeTimeout:
            log.Println("Request timeout")
        case httpc.ErrorTypeNetwork:
            log.Println("Network error")
        case httpc.ErrorTypeTLS:
            log.Println("TLS error")
        case httpc.ErrorTypeCertificate:
            log.Println("Certificate verification failed")
        case httpc.ErrorTypeDNS:
            log.Println("DNS resolution failed")
        case httpc.ErrorTypeRetryExhausted:
            log.Println("Retries exhausted")
        case httpc.ErrorTypeContextCanceled:
            log.Println("Request canceled")
        case httpc.ErrorTypeValidation:
            log.Println("Request validation failed")
        }
    }
}

Error Variables

Configuration Errors

VariableDescription
ErrNilConfigConfiguration is nil
ErrInvalidTimeoutInvalid timeout value
ErrInvalidRetryInvalid retry configuration
ErrInvalidConnectionInvalid connection configuration
ErrInvalidSecurityInvalid security configuration
ErrInvalidMiddlewareInvalid middleware configuration

Request Errors

VariableDescription
ErrInvalidHeaderHeader validation failed

Response Errors

VariableDescription
ErrResponseBodyEmptyResponse body is empty
ErrResponseBodyTooLargeResponse body exceeds size limit

File Errors

VariableDescription
ErrEmptyFilePathFile path is empty
ErrFileExistsFile already exists

Client Errors

VariableDescription
ErrClientClosedClient is closed

Variable Matching

go
if errors.Is(err, httpc.ErrClientClosed) {
    // Client is closed
}
if errors.Is(err, httpc.ErrResponseBodyEmpty) {
    // Response body is empty
}

See Also