http

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package http provides HTTP-related error utilities for the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetErrorFromRequest

func GetErrorFromRequest(resp *http.Response, body []byte) error

GetErrorFromRequest extracts an error from a failed HTTP request. It creates an appropriate error type based on the response status code.

func WriteError

func WriteError(w http.ResponseWriter, err error)

WriteError writes an error response to the HTTP response writer. It sets the appropriate status code and content type, and writes the error as JSON.

func WriteErrorWithStatus

func WriteErrorWithStatus(w http.ResponseWriter, err error, status int)

WriteErrorWithStatus writes an error response with a specific status code. This is useful when you want to override the default status code mapping.

Types

type ErrorResponse

type ErrorResponse struct {
	// Code is the error code
	Code string `json:"code,omitempty"`

	// Message is the error message
	Message string `json:"message,omitempty"`

	// Details contains additional information about the error
	Details map[string]interface{} `json:"details,omitempty"`
}

ErrorResponse represents an error response to be sent to clients.

Jump to

Keyboard shortcuts

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