...

Package utils

import "github.com/chaos-mesh/chaos-mesh/pkg/apiserver/utils"
Overview
Index

Overview ▾

Variables

var (
    ErrNS             = errorx.NewNamespace("error.api")
    ErrUnknown        = ErrNS.NewType("unknown")
    ErrInvalidRequest = ErrNS.NewType("invalid_request")
    ErrInternalServer = ErrNS.NewType("internal_server_error")
    ErrNotFound       = ErrNS.NewType("resource_not_found")
)

func MWHandleErrors

func MWHandleErrors() gin.HandlerFunc

MWHandleErrors creates a middleware that turns (last) error in the context into an APIError json response. In handlers, `c.Error(err)` can be used to attach the error to the context. When error is attached in the context: - The handler can optionally assign the HTTP status code. - The handler must not self-generate a response body.

type APIError

type APIError struct {
    Message  string `json:"message"`
    Code     string `json:"code"`
    FullText string `json:"full_text"`
    Status   string `json:"status"`
}