errutil

package
v0.12.10 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

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

func ApiStatus(err error) int

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

func IsConflictError(err error) bool

IsConflictError reports whether err represents a conflict / already-exists condition.

Classification order:

  1. Error message matches conflictPatterns (primary signal).
  2. Error wraps *client.HttpError with StatusCode 409 (fallback).

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError reports whether err represents a "resource not found" condition.

Classification order:

  1. Error message matches notFoundPatterns (primary signal).
  2. Error wraps *client.HttpError with StatusCode 404 (fallback).

Types

type HttpError

type HttpError struct {
	StatusCode int
	Err        error
}

HttpError carries the HTTP status code from a downstream response so callers can inspect it via errors.As without relying solely on string matching.

func (*HttpError) Error

func (e *HttpError) Error() string

func (*HttpError) Unwrap

func (e *HttpError) Unwrap() error

Jump to

Keyboard shortcuts

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