Documentation
¶
Index ¶
- Variables
- func BadRequest(w http.ResponseWriter, errMsg string)
- func Forbidden(w http.ResponseWriter, errMsg string)
- func HandleErrorWithContext(ctx context.Context, w http.ResponseWriter, err error)
- func HandleSrvcError(logger *slog.Logger, w http.ResponseWriter, err error)
- func InternalError(w http.ResponseWriter)
- func Success(w http.ResponseWriter, data any) error
- func Unauthorized(w http.ResponseWriter, errMsg string)
- func WriteCustom(w http.ResponseWriter, errMsg string, statusCode int, errCode string) error
- func WriteError(w http.ResponseWriter, err error)
- type HttpError
- type HttpStatusCoder
- type JsonResponse
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInternalServerError = HttpError{ ErrCode: "internal_server_error", ErrMsg: "internal server error; please contact the administrator", HttpStatus: http.StatusInternalServerError, } ErrHttpBadRequest = HttpError{ ErrCode: "http_bad_request", ErrMsg: "bad request", HttpStatus: http.StatusBadRequest, } ErrHttpForbidden = HttpError{ ErrCode: "http_forbidden", ErrMsg: "forbidden", HttpStatus: http.StatusForbidden, } ErrCode: "http_unauthorized", ErrMsg: "unauthorized", HttpStatus: http.StatusUnauthorized, } )
Functions ¶
func BadRequest ¶
func BadRequest(w http.ResponseWriter, errMsg string)
shorthand for jsonresp.FromError(w, ErrHttpBadRequest.WithMsg(errMsg))
func Forbidden ¶
func Forbidden(w http.ResponseWriter, errMsg string)
shorthand for jsonresp.FromError(w, ErrHttpForbidden.WithMsg(errMsg))
func HandleErrorWithContext ¶
func HandleErrorWithContext(ctx context.Context, w http.ResponseWriter, err error)
HandleErrorWithContext is a convenience function that extracts the logger from the context
func HandleSrvcError ¶
func HandleSrvcError(logger *slog.Logger, w http.ResponseWriter, err error)
HandleSrvcError handles service errors and writes appropriate HTTP responses
func InternalError ¶
func InternalError(w http.ResponseWriter)
shorthand for jsonresp.FromError(w, ErrInternalServerError)
func Unauthorized ¶
func Unauthorized(w http.ResponseWriter, errMsg string)
shorthand for jsonresp.FromError(w, ErrHttpUnauthorized.WithMsg(errMsg))
func WriteCustom ¶
func WriteError ¶
func WriteError(w http.ResponseWriter, err error)
assume error implements httpStatusCoder interface
Types ¶
type HttpError ¶
type HttpError struct {
ErrCode string // short well-formatted identifier
ErrMsg string
HttpStatus int
}
func (HttpError) HttpStatusCode ¶
type HttpStatusCoder ¶
Click to show internal directories.
Click to hide internal directories.