httperr

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package httperr centralises the mapping from UniRate client errors to an HTTP status code and a JSON-serialisable error body. All three framework adapters (gin, echo, fiber) share this logic so error mapping stays identical across them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Body

type Body struct {
	Error  string `json:"error"`
	Status int    `json:"status"`
}

Body is the JSON error envelope returned to clients.

func Map

func Map(err error) (int, Body)

Map inspects a UniRate client error and returns the HTTP status code and the JSON body to emit. It never returns a zero status: unclassified errors map to 500.

The mapping follows the canonical spec:

400 -> ErrInvalidDate      "Invalid request parameters"
401 -> ErrAuthentication   "Missing or invalid API key"
403 -> APIError(403)       "Endpoint requires a Pro subscription"
404 -> ErrInvalidCurrency  "Currency not found or no data available"
429 -> ErrRateLimit        "Rate limit exceeded"
503 -> APIError(503)       "Service unavailable"
other APIError             pass through its status
network / unknown          500 "Internal server error"

Jump to

Keyboard shortcuts

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