Documentation ¶
Index ¶
- Constants
- func EncodeJSONResponse(_ context.Context, w http.ResponseWriter, response interface{}) error
- func GetDefaultErrorHTTPStatusCode(err error) (s int)
- func NewHTTPErrorJSONEncoder(getHTTPStatus GetHTTPStatusFunc, parseErrorFunc ParseErrorFunc) func(context.Context, error, http.ResponseWriter)
- type BaseEndpointResponse
- type ErrorDescription
- type GetHTTPStatusFunc
- type ParseErrorFunc
Constants ¶
const ( // ErrCodeInternal is returned when an internal error happens. ErrCodeInternal = errors.Code("INTERNAL_ERROR") // ErrCodeBadRequest is returned when an error happens due to request data. ErrCodeBadRequest = errors.Code("BAD_REQUEST") // ErrCodeTimeout is returned then the request returns an error due to a timeout. ErrCodeTimeout = errors.Code("REQUEST_TIMEOUT") )
Variables ¶
This section is empty.
Functions ¶
func EncodeJSONResponse ¶
func EncodeJSONResponse(_ context.Context, w http.ResponseWriter, response interface{}) error
EncodeJSONResponse encodes an endpoint response into json
func GetDefaultErrorHTTPStatusCode ¶
GetDefaultErrorHTTPStatusCode returns an HTTP status code base on an error.
This is a default implementation that sets the satus code base on the error severity. nolint:gocritic
func NewHTTPErrorJSONEncoder ¶
func NewHTTPErrorJSONEncoder( getHTTPStatus GetHTTPStatusFunc, parseErrorFunc ParseErrorFunc, ) func(context.Context, error, http.ResponseWriter)
NewHTTPErrorJSONEncoder returns a new
Types ¶
type BaseEndpointResponse ¶
type BaseEndpointResponse struct { // Example: "51e8cb62dbc57774a7720ef828e96c34" TraceID trace.ID `json:"trace_id,omitempty"` // [Legacy] Already exists in Trace. Trace trace.Trace `json:"trace,omitempty"` RequestID request.ID `json:"request_id,omitempty"` }
BaseEndpointResponse should be used to extend responses from endpoint
func CreateBaseEndpointResponse ¶
func CreateBaseEndpointResponse(ctx context.Context) BaseEndpointResponse
CreateBaseEndpointResponse creates and returns a struct of BaseEndpointResponse filled with data from context and error.
type ErrorDescription ¶
ErrorDescription represents the detailed returned error in all APIs
func ParseError ¶
func ParseError(err error) ErrorDescription
ParseError parses @err in a ErrorDescription
type GetHTTPStatusFunc ¶
GetHTTPStatusFunc is a type of function that should take an error and return an HTTP status code.
type ParseErrorFunc ¶
ParseErrorFunc is a type of function that should take an error parses in a struct.