Improve API error handling.

This commit is contained in:
Yang Luo
2021-03-28 00:48:34 +08:00
parent 6c2c5be33d
commit d6715c7601
18 changed files with 54 additions and 69 deletions

View File

@ -22,6 +22,8 @@ import (
"github.com/astaxie/beego/context"
"github.com/casdoor/casdoor/authz"
"github.com/casdoor/casdoor/controllers"
"github.com/casdoor/casdoor/util"
)
type Object struct {
@ -91,7 +93,8 @@ func getObject(ctx *context.Context) (string, string) {
func denyRequest(ctx *context.Context) {
w := ctx.ResponseWriter
w.WriteHeader(403)
_, err := w.Write([]byte("403 Forbidden\n"))
resp := &controllers.Response{Status: "error", Msg: "unauthorized operation"}
_, err := w.Write([]byte(util.StructToJson(resp)))
if err != nil {
panic(err)
}