apierr

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 2 Imported by: ? modules, 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 apierr provides a standardised error response format for the QubicDB HTTP API.

Every error response returned by the API uses the same JSON envelope:

{
  "ok":       false,
  "error":    "human-readable description",
  "code":     "MACHINE_READABLE_CODE",
  "status":   400
}

This makes error handling predictable for all API consumers — clients can branch on the "code" field for programmatic handling and show the "error" field to humans.

Index

Constants

View Source
const (
	// General
	CodeBadRequest       = "BAD_REQUEST"
	CodeInvalidJSON      = "INVALID_JSON"
	CodeInvalidContent   = "INVALID_CONTENT"
	CodePayloadTooLarge  = "PAYLOAD_TOO_LARGE"
	CodeMethodNotAllowed = "METHOD_NOT_ALLOWED"
	CodeNotFound         = "NOT_FOUND"
	CodeInternalError    = "INTERNAL_ERROR"
	CodeUnauthorized     = "UNAUTHORIZED"
	CodeRateLimited      = "RATE_LIMITED"
	CodeConflict         = "CONFLICT"
	CodeMutationDisabled = "MUTATION_DISABLED"

	// Brain / Neuron domain
	CodeIndexIDRequired  = "INDEX_ID_REQUIRED"
	CodeNeuronIDRequired = "NEURON_ID_REQUIRED"
	CodeNeuronNotFound   = "NEURON_NOT_FOUND"
	CodeQueryRequired    = "QUERY_REQUIRED"
	CodeUUIDRequired     = "UUID_REQUIRED"

	// Registry domain
	CodeUUIDNotRegistered = "UUID_NOT_REGISTERED"
	CodeUUIDNotFound      = "UUID_NOT_FOUND"
	CodeUUIDConflict      = "UUID_CONFLICT"
)

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(w http.ResponseWriter, code, msg string)

BadRequest writes a 400 response with the given code and message.

func Conflict

func Conflict(w http.ResponseWriter, code, msg string)

Conflict writes a 409 response.

func IndexIDRequired

func IndexIDRequired(w http.ResponseWriter)

IndexIDRequired writes a 400 response when X-Index-ID is missing.

func Internal

func Internal(w http.ResponseWriter, msg string)

Internal writes a 500 response.

func InvalidJSON

func InvalidJSON(w http.ResponseWriter)

InvalidJSON writes a 400 response for malformed request bodies.

func MethodNotAllowed

func MethodNotAllowed(w http.ResponseWriter)

MethodNotAllowed writes a 405 response.

func NeuronIDRequired

func NeuronIDRequired(w http.ResponseWriter)

NeuronIDRequired writes a 400 response when a neuron ID is missing.

func NotFound

func NotFound(w http.ResponseWriter, code, msg string)

NotFound writes a 404 response.

func PayloadTooLarge

func PayloadTooLarge(w http.ResponseWriter, msg string)

PayloadTooLarge writes a 413 response when body/content exceeds configured bounds.

func QueryRequired

func QueryRequired(w http.ResponseWriter)

QueryRequired writes a 400 response when a search query is empty.

func TooManyRequests

func TooManyRequests(w http.ResponseWriter, msg string)

TooManyRequests writes a 429 response.

func UUIDRequired

func UUIDRequired(w http.ResponseWriter)

UUIDRequired writes a 400 response when a UUID is missing.

func Unauthorized

func Unauthorized(w http.ResponseWriter, msg string)

Unauthorized writes a 401 response.

func Write

func Write(w http.ResponseWriter, status int, code, message string)

Write serialises an error Response and writes it to w with the appropriate HTTP status code. Content-Type is always set to application/json.

Types

type Response

type Response struct {
	OK     bool   `json:"ok"`
	Error  string `json:"error"`
	Code   string `json:"code"`
	Status int    `json:"status"`
}

Response is the standard error envelope returned to API clients.

Jump to

Keyboard shortcuts

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