parse 401 err, change code to 428

Signed-off-by: runzexia <runzexia@yunify.com>
This commit is contained in:
runzexia
2019-09-27 23:50:07 +08:00
parent 416719aae3
commit f6c616f1e9

View File

@@ -172,14 +172,20 @@ func Validate(req *restful.Request, resp *restful.Response) {
res, err := devops.Validate(scmId, req.Request)
if err != nil {
parseErr(err, resp)
log.Error(err)
if jErr, ok := err.(*devops.JkError); ok {
if jErr.Code != http.StatusUnauthorized {
resp.WriteError(jErr.Code, err)
} else {
resp.WriteHeader(http.StatusPreconditionRequired)
}
} else {
resp.WriteError(http.StatusInternalServerError, err)
}
return
}
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
if resp.StatusCode() == http.StatusUnauthorized {
resp.WriteHeader(http.StatusPreconditionRequired)
}
resp.Write(res)
}