middleware

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2025 License: Apache-2.0, MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleError

func HandleError(err error, c echo.Context)

HandleError converts any error to an HTTP response It's especially helpful for handling our custom ContextualError

func LogMiddleware

func LogMiddleware(logger *logging.ZapEventLogger) echo.MiddlewareFunc

LogMiddleware returns a middleware that logs requests using the IPFS go-log logger

Types

type ContextualError

type ContextualError interface {
	error
	// StatusCode returns the HTTP status code that should be returned to the client
	StatusCode() int
	// LogContext returns a map of additional context for logging
	LogContext() map[string]interface{}
	// PublicMessage returns a message safe to return to the client
	PublicMessage() string
	// OriginalError returns the underlying error, if any
	OriginalError() error
}

ContextualError is a richer error interface that provides additional context about an error that occurred during request handling.

type PDPError

type PDPError struct {
	Operation     string                 // The operation that failed (e.g., "ProofSetAddRoot")
	Message       string                 // Internal error message (for logs)
	ClientMessage string                 // Message safe to return to clients
	Code          int                    // HTTP status code
	Err           error                  // Original error, if any
	Context       map[string]interface{} // Additional context for logging
}

PDPError implements the ContextualError interface

func NewError

func NewError(operation string, message string, err error, code int) *PDPError

NewError creates a new PDPError

func (*PDPError) Error

func (e *PDPError) Error() string

Error satisfies the error interface

func (*PDPError) LogContext

func (e *PDPError) LogContext() map[string]interface{}

LogContext returns context information for logging

func (*PDPError) OriginalError

func (e *PDPError) OriginalError() error

OriginalError returns the underlying error

func (*PDPError) PublicMessage

func (e *PDPError) PublicMessage() string

PublicMessage returns a message safe for client consumption

func (*PDPError) StatusCode

func (e *PDPError) StatusCode() int

StatusCode returns the HTTP status code

func (*PDPError) WithContext

func (e *PDPError) WithContext(key string, value interface{}) *PDPError

WithContext adds context information to the error

func (*PDPError) WithPublicMessage

func (e *PDPError) WithPublicMessage(message string) *PDPError

WithPublicMessage sets a client-safe message

Jump to

Keyboard shortcuts

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