errors

package
v0.69.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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