1 Star 0 Fork 0

ryancartoon/sensu-go

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
error.go 906 Bytes
一键复制 编辑 原始数据 按行查看 历史
Cyril Cressent 提交于 2018-11-24 02:19 +08:00 . Complete redesign of RBAC (#2338)
package middlewares
import (
"encoding/json"
"net/http"
"github.com/sensu/sensu-go/backend/apid/actions"
)
func writeErr(w http.ResponseWriter, err error) {
var errRes actions.Error
if erro, ok := err.(actions.Error); ok {
errRes = erro
} else {
errRes = actions.Error{
Code: actions.InternalErr,
Message: err.Error(),
}
}
var st int
switch errRes.Code {
case actions.InternalErr:
st = http.StatusInternalServerError
case actions.InvalidArgument:
st = http.StatusBadRequest
case actions.NotFound:
st = http.StatusNotFound
case actions.AlreadyExistsErr:
st = http.StatusConflict
case actions.PermissionDenied:
st = http.StatusForbidden
case actions.Unauthenticated:
st = http.StatusUnauthorized
}
errJSON, err := json.Marshal(errRes)
if err != nil {
logger.WithError(err).Error("unable to marshal error")
}
w.WriteHeader(st)
_, _ = w.Write(errJSON)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ryancartoon/sensu-go.git
git@gitee.com:ryancartoon/sensu-go.git
ryancartoon
sensu-go
sensu-go
v5.10.1

搜索帮助