response

package
v0.1.51 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

response/error.go This package provides utility functions and structures for handling and categorizing HTTP error responses.

response/parse.go

response/success.go

Responsible for handling successful API responses. It reads the response body, logs the raw response details,

and unmarshals the response based on the content type (JSON or XML).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleAPISuccessResponse added in v0.1.14

func HandleAPISuccessResponse(resp *http.Response, out interface{}, log logger.Logger) error

HandleAPISuccessResponse reads the response body, logs the raw response details, and unmarshals the response based on the content type.

func ParseContentDisposition added in v0.1.17

func ParseContentDisposition(header string) (string, map[string]string)

ParseContentDisposition parses the Content-Disposition header and returns the type and any parameters.

func ParseContentTypeHeader added in v0.1.7

func ParseContentTypeHeader(header string) (string, map[string]string)

ParseContentTypeHeader parses the Content-Type header and returns the MIME type and any parameters.

Types

type APIError

type APIError struct {
	StatusCode  int      `json:"status_code"`       // HTTP status code
	Method      string   `json:"method"`            // HTTP method used for the request
	URL         string   `json:"url"`               // The URL of the HTTP request
	Message     string   `json:"message"`           // Summary of the error
	Details     []string `json:"details,omitempty"` // Detailed error messages, if any
	RawResponse string   `json:"raw_response"`      // Raw response body for debugging
}

APIError represents an api error response.

func HandleAPIErrorResponse

func HandleAPIErrorResponse(resp *http.Response, log logger.Logger) *APIError

HandleAPIErrorResponse handles the HTTP error response from an API and logs the error.

func (*APIError) Error

func (e *APIError) Error() string

Error returns a string representation of the APIError, making it compatible with the error interface.

Jump to

Keyboard shortcuts

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