Simplify REST errors
This commit is contained in:
parent
6dc0f90e98
commit
2bf8471712
1 changed files with 9 additions and 6 deletions
|
@ -23,14 +23,12 @@ func output(c *fibre.Context, res interface{}) error {
|
||||||
switch ret := res.(*db.Response); ret.Status {
|
switch ret := res.(*db.Response); ret.Status {
|
||||||
case "OK":
|
case "OK":
|
||||||
return c.Send(200, ret.Result)
|
return c.Send(200, ret.Result)
|
||||||
case "ERR_CODE":
|
case "ERR_DB":
|
||||||
return c.Send(500, oops(500, ret.Detail))
|
return fibre.NewHTTPError(500)
|
||||||
case "ERR_JSON":
|
|
||||||
return fibre.NewHTTPError(422)
|
|
||||||
case "ERR_EXISTS":
|
case "ERR_EXISTS":
|
||||||
return fibre.NewHTTPError(409)
|
return fibre.NewHTTPError(409)
|
||||||
default:
|
default:
|
||||||
return fibre.NewHTTPError(500)
|
return fibre.NewHTTPError(400)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +49,12 @@ func routes(s *fibre.Fibre) {
|
||||||
s.Post("/sql", func(c *fibre.Context) error {
|
s.Post("/sql", func(c *fibre.Context) error {
|
||||||
res, err := db.Execute(c, c.Request().Body)
|
res, err := db.Execute(c, c.Request().Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fibre.NewHTTPError(400)
|
return c.Send(400, map[string]interface{}{
|
||||||
|
"code": 400,
|
||||||
|
"details": "Request problems detected",
|
||||||
|
"documentation": "https://docs.surreal.io/",
|
||||||
|
"information": err.Error(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return c.Send(200, res)
|
return c.Send(200, res)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue