Documentation
¶
Overview ¶
Package errutil classifies errors from downstream services (Spider, CSP, KV store) and maps them to HTTP status codes for Tumblebug API responses.
Usage:
In resource layer: log downstream origin, return a clean domain message
if err = clientManager.HandleHttpResponse(resp, err); err != nil {
log.Error().Err(err).Msg("") // preserves raw text
return fmt.Errorf("failed to create vNet '%s'", id) // clean domain message
}
In REST handler: map error to HTTP status code
return c.JSON(errutil.ApiStatus(err), model.SimpleMsg{Message: err.Error()})
→ 404 "not found / does not exist", 409 "already exists / conflict", 500 otherwise
HttpError is defined here and wrapped by client.HandleHttpResponse to carry the HTTP status code as a fallback when the error message does not match a known pattern.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApiStatus ¶
ApiStatus maps err to an HTTP status code for Tumblebug API responses.
Only semantically meaningful domain errors (404, 409) are surfaced to API callers; everything else becomes 500. This ensures that Spider's internal codes and raw CSP messages are never exposed directly to the caller — the mapping is driven solely by the pattern lists above.
Used exclusively in REST handlers (interface/rest/server/resource/).
func IsConflictError ¶
IsConflictError reports whether err represents a conflict / already-exists condition.
Classification order:
- Error message matches conflictPatterns (primary signal).
- Error wraps *client.HttpError with StatusCode 409 (fallback).
func IsNotFoundError ¶
IsNotFoundError reports whether err represents a "resource not found" condition.
Classification order:
- Error message matches notFoundPatterns (primary signal).
- Error wraps *client.HttpError with StatusCode 404 (fallback).