response

package
v0.0.0-...-efbd42f Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

The response package defines the success and error response type. It define a type [AppError] that represent the api error response. Its define a custom error handling for the api.

The response package defines the success and error response type.

Index

Constants

View Source
const (
	OK = iota
	Canceled
	Unknown
	InvalidParam
	DeadlineExceeded
	NotFound
	AlreadyExists
	PermissionDenied
	ResourceExhausted
	FailedPrecondition
	Aborted
	OutOfRange
	Unimplemented
	Internal
	Unavailable
	DataLoss
	Unauthenticated
)

API error codes. These error code are the same used in phylax API. https://github.com/grpc/grpc-go/blob/master/codes/codes.go

Variables

This section is empty.

Functions

func SetEnableStackTrace

func SetEnableStackTrace(cfg config.AppConfig)

SetEnableStackTrace enable/disable send the stacktrace field in the response.

Types

type APIError

type APIError struct {
	StatusCode int           `json:"-"`
	Code       int           `json:"code"` // support to phylax-api code.
	Message    string        `json:"message"`
	Details    []ErrorDetail `json:"details"`
}

APIError api error response. This structure is defined to be aligned with the way the phylax API handles the error response.

func NewApiError

func NewApiError(ctx *fiber.Ctx, statusCode, code int, message string, err error) APIError

NewApiError create a new api response.

func NewInternalError

func NewInternalError(ctx *fiber.Ctx, err error) APIError

NewInternalError create a new APIError for Internal Errors.

func NewInvalidParamError

func NewInvalidParamError(ctx *fiber.Ctx, message string, err error) APIError

NewInvalidParamError create a invalid param Error.

func NewInvalidQueryParamError

func NewInvalidQueryParamError(ctx *fiber.Ctx, message string, err error) APIError

NewInvalidQueryParamError create a query param error

func NewNotFoundError

func NewNotFoundError(ctx *fiber.Ctx) APIError

NewNotFoundError create a new APIError for Not Found errors.

func NewRequestBodyError

func NewRequestBodyError(ctx *fiber.Ctx, message string, err error) APIError

func (APIError) Error

func (a APIError) Error() string

Error interface implementation.

type ErrorDetail

type ErrorDetail struct {
	RequestID  string `json:"request_id"`
	StackTrace string `json:"stack_trace,omitempty"`
}

ErrorDetail definition. This structure contains the requestID and the stacktrace of the error.

type Response

type Response[T any] struct {
	Data       T                  `json:"data"`
	Pagination ResponsePagination `json:"pagination"`
}

Response represent a success API response.

type ResponsePagination

type ResponsePagination struct {
	Next string `json:"next"`
}

ResponsePagination definition.

Jump to

Keyboard shortcuts

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