Documentation
¶
Index ¶
- type APIError
- func (e *APIError) Response() *APIErrorResponse
- func (e *APIError) WithDetail(key string, value any) *APIError
- func (e *APIError) WithDetails(details map[string]any) *APIError
- func (e *APIError) WithMessage(message string) *APIError
- func (e *APIError) WithSuggestions(suggestions ...string) *APIError
- type APIErrorResponse
- type APIValidationError
- type ErrorCode
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
// Machine-readable error code (e.g., "REPO_NOT_FOUND")
Code string `json:"code"`
// Human-readable error message
Message string `json:"message"`
// HTTP status code
Status int `json:"status"`
// Additional context about the error
Details map[string]any `json:"details,omitempty"`
// URL to documentation about this error
DocumentationURL string `json:"documentation_url,omitempty"`
// Unique request ID for tracing
RequestID string `json:"request_id,omitempty"`
// Suggested actions or alternatives
Suggestions []string `json:"suggestions,omitempty"`
// RFC 7807 Problem Details fields
Type string `json:"type,omitempty"` // URI reference identifying the problem type
Title string `json:"title,omitempty"` // Short summary of the problem type
Instance string `json:"instance,omitempty"` // URI reference for this specific occurrence
}
APIError represents a structured API error following RFC 7807 Problem Details with additional fields for AI-friendly error handling
func NewAPIError ¶
NewAPIError creates a new structured API error
func (*APIError) Response ¶
func (e *APIError) Response() *APIErrorResponse
Response wraps the error in an APIErrorResponse
func (*APIError) WithDetail ¶
WithDetail adds a single detail to the error
func (*APIError) WithDetails ¶
WithDetails adds details to the error
func (*APIError) WithMessage ¶
WithMessage overrides the default message
type APIErrorResponse ¶
type APIErrorResponse struct {
Error *APIError `json:"error"`
}
APIErrorResponse is the top-level error response wrapper
type APIValidationError ¶
type APIValidationError struct {
*APIError
Errors []ValidationError `json:"errors,omitempty"`
}
APIValidationError represents a validation error with field-level details
func NewValidationError ¶
func NewValidationError(requestID string, errors ...ValidationError) *APIValidationError
NewValidationError creates a new validation error
func (*APIValidationError) AddFieldError ¶
func (e *APIValidationError) AddFieldError(field, message string, code ...string) *APIValidationError
AddFieldError adds a field validation error
type ErrorCode ¶
type ErrorCode string
ErrorCode represents a machine-readable error code
const ( AuthTokenMissing ErrorCode = "AUTH_TOKEN_MISSING" AuthTokenInvalid ErrorCode = "AUTH_TOKEN_INVALID" AuthTokenExpired ErrorCode = "AUTH_TOKEN_EXPIRED" AuthScopeInsufficient ErrorCode = "AUTH_SCOPE_INSUFFICIENT" Auth2FARequired ErrorCode = "AUTH_2FA_REQUIRED" AuthInvalidCredentials ErrorCode = "AUTH_INVALID_CREDENTIALS" )
Authentication errors (AUTH_)
const ( PermRepoReadDenied ErrorCode = "PERM_REPO_READ_DENIED" PermRepoWriteDenied ErrorCode = "PERM_REPO_WRITE_DENIED" PermRepoAdminRequired ErrorCode = "PERM_REPO_ADMIN_REQUIRED" PermOrgMemberRequired ErrorCode = "PERM_ORG_MEMBER_REQUIRED" PermOrgAdminRequired ErrorCode = "PERM_ORG_ADMIN_REQUIRED" PermActionDenied ErrorCode = "PERM_ACTION_DENIED" )
Permission errors (PERM_)
const ( RepoNotFound ErrorCode = "REPO_NOT_FOUND" RepoArchived ErrorCode = "REPO_ARCHIVED" RepoDisabled ErrorCode = "REPO_DISABLED" RepoTransferPending ErrorCode = "REPO_TRANSFER_PENDING" RepoEmpty ErrorCode = "REPO_EMPTY" RepoAlreadyExists ErrorCode = "REPO_ALREADY_EXISTS" )
Repository errors (REPO_)
const ( FileNotFound ErrorCode = "FILE_NOT_FOUND" FileTooLarge ErrorCode = "FILE_TOO_LARGE" FileConflict ErrorCode = "FILE_CONFLICT" FileBinary ErrorCode = "FILE_BINARY" FileTypeError ErrorCode = "FILE_TYPE_NOT_ALLOWED" )
File errors (FILE_)
const ( GitRefNotFound ErrorCode = "GIT_REF_NOT_FOUND" GitMergeConflict ErrorCode = "GIT_MERGE_CONFLICT" GitBranchNotFound ErrorCode = "GIT_BRANCH_NOT_FOUND" GitTagNotFound ErrorCode = "GIT_TAG_NOT_FOUND" GitCommitNotFound ErrorCode = "GIT_COMMIT_NOT_FOUND" GitPushRejected ErrorCode = "GIT_PUSH_REJECTED" )
Git errors (GIT_)
const ( RateLimitExceeded ErrorCode = "RATE_LIMIT_EXCEEDED" RateQuotaExhausted ErrorCode = "RATE_QUOTA_EXHAUSTED" )
Rate limiting errors (RATE_)
const ( ValInvalidInput ErrorCode = "VAL_INVALID_INPUT" ValMissingField ErrorCode = "VAL_MISSING_FIELD" ValInvalidName ErrorCode = "VAL_INVALID_NAME" ValNameTooLong ErrorCode = "VAL_NAME_TOO_LONG" ValInvalidEmail ErrorCode = "VAL_INVALID_EMAIL" ValDuplicateName ErrorCode = "VAL_DUPLICATE_NAME" ValInvalidFormat ErrorCode = "VAL_INVALID_FORMAT" ValidationFailed ErrorCode = "VALIDATION_FAILED" )
Validation errors (VAL_)
const ( InternalError ErrorCode = "INTERNAL_ERROR" PermAccessDenied ErrorCode = "ACCESS_DENIED" RefNotFound ErrorCode = "REF_NOT_FOUND" )
General errors
const ( UploadSessionNotFound ErrorCode = "UPLOAD_SESSION_NOT_FOUND" UploadSessionExpired ErrorCode = "UPLOAD_SESSION_EXPIRED" UploadChunkInvalid ErrorCode = "UPLOAD_CHUNK_INVALID" UploadChunkSizeMismatch ErrorCode = "UPLOAD_CHUNK_SIZE_MISMATCH" UploadChecksumMismatch ErrorCode = "UPLOAD_CHECKSUM_MISMATCH" UploadIncomplete ErrorCode = "UPLOAD_INCOMPLETE" UploadFileTooLarge ErrorCode = "UPLOAD_FILE_TOO_LARGE" )
Upload errors (UPLOAD_)
const ( ResourceNotFound ErrorCode = "RESOURCE_NOT_FOUND" ResourceConflict ErrorCode = "RESOURCE_CONFLICT" ResourceGone ErrorCode = "RESOURCE_GONE" )
Resource errors (RESOURCE_)
const ( ServerInternal ErrorCode = "SERVER_INTERNAL_ERROR" ServerTimeout ErrorCode = "SERVER_TIMEOUT" )
Server errors (SERVER_)
const ( UserNotFound ErrorCode = "USER_NOT_FOUND" UserAlreadyExists ErrorCode = "USER_ALREADY_EXISTS" UserInactive ErrorCode = "USER_INACTIVE" UserProhibitLogin ErrorCode = "USER_PROHIBIT_LOGIN" )
User errors (USER_)
Organization errors (ORG_)
const ( IssueNotFound ErrorCode = "ISSUE_NOT_FOUND" IssueClosed ErrorCode = "ISSUE_CLOSED" IssueLocked ErrorCode = "ISSUE_LOCKED" )
Issue errors (ISSUE_)
const ( PRNotFound ErrorCode = "PR_NOT_FOUND" PRAlreadyMerged ErrorCode = "PR_ALREADY_MERGED" PRNotMergeable ErrorCode = "PR_NOT_MERGEABLE" PRWorkInProgress ErrorCode = "PR_WORK_IN_PROGRESS" )
Pull Request errors (PR_)
const ( ReleaseNotFound ErrorCode = "RELEASE_NOT_FOUND" ReleaseTagExists ErrorCode = "RELEASE_TAG_EXISTS" ReleaseIsDraft ErrorCode = "RELEASE_IS_DRAFT" )
Release errors (RELEASE_)
const ( WebhookNotFound ErrorCode = "WEBHOOK_NOT_FOUND" WebhookDeliveryFail ErrorCode = "WEBHOOK_DELIVERY_FAILED" )
Webhook errors (WEBHOOK_)
const ( WikiPageNotFound ErrorCode = "WIKI_PAGE_NOT_FOUND" WikiPageAlreadyExists ErrorCode = "WIKI_PAGE_ALREADY_EXISTS" WikiReservedName ErrorCode = "WIKI_RESERVED_NAME" WikiDisabled ErrorCode = "WIKI_DISABLED" )
Wiki errors (WIKI_)
func (ErrorCode) HTTPStatus ¶
HTTPStatus returns the HTTP status code for an error code
func (ErrorCode) IsValid ¶
IsValid returns true if the error code is registered in the catalog
func (ErrorCode) Message ¶
Message returns the human-readable message for an error code
Source Files
¶
- api_error.go
- codes.go