micw/server/logic/err/err.go
2024-11-13 22:10:13 +01:00

29 lines
425 B
Go

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)
}