errors

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target interface{}) bool

As is a convenience wrapper around errors.As from the standard library. It finds the first error in err's chain that matches target's type.

func IsAPIError

func IsAPIError(err error) bool

IsAPIError checks if an error is or wraps an APIError.

func IsAuthError

func IsAuthError(err error) bool

IsAuthError checks if an error is or wraps an AuthError.

func IsNetworkError

func IsNetworkError(err error) bool

IsNetworkError checks if an error is or wraps a NetworkError.

func IsVerboseMode

func IsVerboseMode() bool

IsVerboseMode returns whether verbose mode is enabled.

func IsVersionError

func IsVersionError(err error) bool

IsVersionError checks if an error is or wraps a VersionError.

func NewLoggingHTTPClient

func NewLoggingHTTPClient() *http.Client

NewLoggingHTTPClient creates an HTTP client that logs requests/responses in verbose mode.

func SetVerboseMode

func SetVerboseMode(enabled bool)

SetVerboseMode enables or disables verbose error output.

func SuggestForAuth

func SuggestForAuth(statusCode int, host string) string

SuggestForAuth returns an actionable suggestion for authentication errors.

func SuggestForNetwork

func SuggestForNetwork(host string) string

SuggestForNetwork returns an actionable suggestion for network errors.

func SuggestForStatusCode

func SuggestForStatusCode(statusCode int) string

SuggestForStatusCode returns an actionable suggestion based on HTTP status code.

func WrapAPIError

func WrapAPIError(err error, method, url string, statusCode int) error

WrapAPIError wraps an existing error with API context. If err is nil, returns nil. If err is already an APIError, returns it unchanged.

Types

type APIError

type APIError struct {
	// Method is the HTTP method (GET, POST, PUT, DELETE, etc.)
	Method string
	// URL is the full request URL that failed
	URL string
	// StatusCode is the HTTP status code from the response
	StatusCode int
	// Message is the error message from the API or a descriptive error
	Message string
	// Suggestion provides actionable guidance to resolve the error
	Suggestion string
	// Err is the underlying error that caused this API error
	Err error
}

APIError represents an error from a GitLab API request with detailed context.

func NewAPIError

func NewAPIError(method, url string, statusCode int, message string, err error) *APIError

NewAPIError creates a new APIError with the given details. The suggestion is automatically generated from the status code if not provided.

func (*APIError) Error

func (e *APIError) Error() string

Error implements the error interface.

func (*APIError) ErrorCode

func (e *APIError) ErrorCode() string

ErrorCode returns the error code for this APIError.

func (*APIError) ErrorDetails

func (e *APIError) ErrorDetails() map[string]interface{}

ErrorDetails returns structured details for JSON error formatting.

func (*APIError) Unwrap

func (e *APIError) Unwrap() error

Unwrap returns the underlying error.

type AuthError

type AuthError struct {
	// Host is the GitLab host where authentication failed
	Host string
	// Method is the HTTP method (GET, POST, PUT, DELETE, etc.)
	Method string
	// URL is the full request URL that failed
	URL string
	// StatusCode is the HTTP status code (typically 401 or 403)
	StatusCode int
	// Message is a descriptive error message
	Message string
	// Suggestion provides actionable guidance to resolve the auth issue
	Suggestion string
	// Err is the underlying error
	Err error
}

AuthError represents an authentication or authorization error.

func NewAuthError

func NewAuthError(host, method, url string, statusCode int, message string, err error) *AuthError

NewAuthError creates a new AuthError with the given details. The suggestion is automatically generated from the status code and host if not provided.

func (*AuthError) Error

func (e *AuthError) Error() string

Error implements the error interface.

func (*AuthError) ErrorCode

func (e *AuthError) ErrorCode() string

ErrorCode returns the error code for this AuthError.

func (*AuthError) ErrorDetails

func (e *AuthError) ErrorDetails() map[string]interface{}

ErrorDetails returns structured details for JSON error formatting.

func (*AuthError) Unwrap

func (e *AuthError) Unwrap() error

Unwrap returns the underlying error.

type NetworkError

type NetworkError struct {
	// Host is the remote host that could not be reached
	Host string
	// URL is the full request URL that failed
	URL string
	// Message is a descriptive error message
	Message string
	// Suggestion provides actionable guidance to resolve the network issue
	Suggestion string
	// Err is the underlying error
	Err error
}

NetworkError represents a network connectivity error.

func NewNetworkError

func NewNetworkError(host, url, message string, err error) *NetworkError

NewNetworkError creates a new NetworkError with the given details. The suggestion is automatically generated from the host if not provided.

func (*NetworkError) Error

func (e *NetworkError) Error() string

Error implements the error interface.

func (*NetworkError) ErrorCode

func (e *NetworkError) ErrorCode() string

ErrorCode returns the error code for this NetworkError.

func (*NetworkError) ErrorDetails

func (e *NetworkError) ErrorDetails() map[string]interface{}

ErrorDetails returns structured details for JSON error formatting.

func (*NetworkError) Unwrap

func (e *NetworkError) Unwrap() error

Unwrap returns the underlying error.

type VersionError

type VersionError struct {
	// RequiredVersion is the minimum GitLab version required
	RequiredVersion string
	// ActualVersion is the detected GitLab version
	ActualVersion string
	// Feature is the feature or operation that requires the minimum version
	Feature string
	// Message is a descriptive error message
	Message string
	// Suggestion provides actionable guidance to resolve the version issue
	Suggestion string
	// Err is the underlying error
	Err error
}

VersionError represents a GitLab API version mismatch error.

func NewVersionError

func NewVersionError(requiredVersion, actualVersion, feature, message string, err error) *VersionError

NewVersionError creates a new VersionError with the given details.

func (*VersionError) Error

func (e *VersionError) Error() string

Error implements the error interface.

func (*VersionError) Unwrap

func (e *VersionError) Unwrap() error

Unwrap returns the underlying error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL