errors

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2023 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRouterStrategyTimeoutExceeded is a FiberError that's returned when
	// the routing strategy fails to respond within given timeout
	ErrRouterStrategyTimeoutExceeded = func(protocol protocol.Protocol) *FiberError {
		statusCode := http.StatusRequestTimeout
		if protocol == "GRPC" {
			statusCode = int(codes.DeadlineExceeded)
		}
		return &FiberError{
			Code:    statusCode,
			Message: "fiber: routing strategy failed to respond within given timeout",
		}
	}

	// ErrRouterStrategyReturnedEmptyRoutes is a FiberError that's returned when
	// the routing strategy returns an empty routes list
	ErrRouterStrategyReturnedEmptyRoutes = func(protocol protocol.Protocol) *FiberError {
		statusCode := http.StatusNotFound
		if protocol == "GRPC" {
			statusCode = int(codes.NotFound)
		}
		return &FiberError{
			Code:    statusCode,
			Message: "fiber: routing strategy returned empty routes list",
		}
	}

	// ErrNoValidResponseFromRoutes is a FiberError that's returned when
	// none of the routes in the routing strategy return a valid response
	ErrNoValidResponseFromRoutes = func(protocol protocol.Protocol) *FiberError {
		statusCode := http.StatusBadGateway
		if protocol == "GRPC" {
			statusCode = int(codes.Unavailable)
		}
		return &FiberError{
			Code:    statusCode,
			Message: "fiber: no valid responses received from routes",
		}
	}

	// ErrRequestTimeout is a FiberError that's returned when
	// no response if received for a given HTTP request within the configured timeout
	ErrRequestTimeout = func(protocol protocol.Protocol) *FiberError {
		statusCode := http.StatusRequestTimeout
		if protocol == "GRPC" {
			statusCode = int(codes.DeadlineExceeded)
		}
		return &FiberError{
			Code:    statusCode,
			Message: "fiber: failed to receive a response within configured timeout",
		}
	}

	// ErrReadRequestFailed is a FiberError that's returned when a request cannot
	// be read successfully
	ErrReadRequestFailed = func(protocol protocol.Protocol, err error) *FiberError {
		statusCode := http.StatusInternalServerError
		if protocol == "GRPC" {
			statusCode = int(codes.Internal)
		}
		return &FiberError{
			Code:    statusCode,
			Message: fmt.Sprintf("fiber: failed to read incoming request: %s", err.Error()),
		}
	}

	// ErrRequestFailed is a generic error that is created when problems are encountered fulfilling
	// a request
	ErrRequestFailed = func(protocol protocol.Protocol, err error) *FiberError {
		statusCode := http.StatusInternalServerError
		if protocol == "GRPC" {
			statusCode = int(codes.Internal)
		}
		return &FiberError{
			Code:    statusCode,
			Message: fmt.Sprintf("fiber: request cannot be completed: %s", err.Error()),
		}
	}

	ErrInvalidInput = func(protocol protocol.Protocol, err error) *FiberError {
		statusCode := http.StatusBadRequest
		if protocol == "GRPC" {
			statusCode = int(codes.InvalidArgument)
		}
		return &FiberError{
			Code:    statusCode,
			Message: fmt.Sprintf("fiber: %s", err.Error()),
		}
	}
)

Functions

This section is empty.

Types

type FiberError added in v0.2.0

type FiberError struct {
	Code    int    `json:"code"`
	Message string `json:"error"`
}

FiberError is used to capture the error resulting from a Fiber request

func NewFiberError added in v0.2.0

func NewFiberError(protocol protocol.Protocol, err error) *FiberError

NewFiberError returns an error of type FiberError from the input error object. If the input error is already of the required type, it is returned as is. If not, a generic request failed error is created from the given error.

func (FiberError) Error added in v0.2.0

func (err FiberError) Error() string

Error is a getter for the error message in a FiberError object

func (*FiberError) ToJSON added in v0.2.0

func (err *FiberError) ToJSON() ([]byte, error)

ToJSON returns the FiberError object as a Json encoded byte array

Jump to

Keyboard shortcuts

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