errors

package
v0.7.1 Latest Latest
Warning

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

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

Documentation

Overview

Package errors provides HTTP error handling utilities for the API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorHandler

func ErrorHandler(fn HandlerWithError) http.HandlerFunc

ErrorHandler wraps a HandlerWithError and converts returned errors into appropriate HTTP responses.

The decorator:

  • Returns early if no error is returned (handler already wrote response)
  • Extracts HTTP status code from the error using errors.Code()
  • For 5xx errors: logs full error details, returns generic message to client
  • For 4xx errors: returns error message to client

Usage:

r.Get("/{name}", apierrors.ErrorHandler(routes.getWorkload))

Types

type HandlerWithError

type HandlerWithError func(http.ResponseWriter, *http.Request) error

HandlerWithError is an HTTP handler that can return an error. This signature allows handlers to return errors instead of manually writing error responses, enabling centralized error handling.

Jump to

Keyboard shortcuts

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