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
- func SetEnableStackTrace(cfg config.AppConfig)
- type APIError
- func NewApiError(ctx *fiber.Ctx, statusCode, code int, message string, err error) APIError
- func NewInternalError(ctx *fiber.Ctx, err error) APIError
- func NewInvalidParamError(ctx *fiber.Ctx, message string, err error) APIError
- func NewInvalidQueryParamError(ctx *fiber.Ctx, message string, err error) APIError
- func NewNotFoundError(ctx *fiber.Ctx) APIError
- func NewRequestBodyError(ctx *fiber.Ctx, message string, err error) APIError
- type ErrorDetail
- type Response
- type ResponsePagination
Constants ¶
const ( OK = iota Canceled Unknown InvalidParam DeadlineExceeded NotFound AlreadyExists PermissionDenied ResourceExhausted FailedPrecondition Aborted OutOfRange Unimplemented Internal 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 ¶
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 ¶
NewApiError create a new api response.
func NewInternalError ¶
NewInternalError create a new APIError for Internal Errors.
func NewInvalidParamError ¶
NewInvalidParamError create a invalid param Error.
func NewInvalidQueryParamError ¶
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 ¶
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.