micw/server/logic/err/err.go

29 lines
425 B
Go
Raw Permalink Normal View History

2024-11-13 21:10:13 +00:00
package logicErr
import (
"context"
"net/http"
)
type Err struct {
error
Msg string
ApiMsg string
Log bool
HttpCode int
}
func (e *Err) Error() string {
return e.Msg
}
func HandleHttp(ctx context.Context, w http.ResponseWriter, r *http.Request, err *Err) {
if err.ApiMsg == "" {
err.ApiMsg = err.Error()
}
if err.Log {
DefaultHttpErrLogger(err, r)
}
http.Error(w, err.ApiMsg, err.HttpCode)
}