Improve error messages on REST API queries
This commit is contained in:
parent
121498e95e
commit
12c2ada091
1 changed files with 26 additions and 6 deletions
|
@ -53,6 +53,8 @@ func Output(c *fibre.Context, t string, d Display, m Method, res []*db.Response,
|
||||||
return fibre.NewHTTPError(403) // Should not happen
|
return fibre.NewHTTPError(403) // Should not happen
|
||||||
case *sql.EmptyError:
|
case *sql.EmptyError:
|
||||||
return fibre.NewHTTPError(500) // Should not happen
|
return fibre.NewHTTPError(500) // Should not happen
|
||||||
|
case *fibre.HTTPError:
|
||||||
|
return err // Probably a timeout error
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(res) == 0 {
|
if len(res) == 0 {
|
||||||
|
@ -90,9 +92,15 @@ func OutputBase(c *fibre.Context, t string, d Display, m Method, res []*db.Respo
|
||||||
case "ERR_DB":
|
case "ERR_DB":
|
||||||
return fibre.NewHTTPError(503)
|
return fibre.NewHTTPError(503)
|
||||||
case "ERR_KV":
|
case "ERR_KV":
|
||||||
return fibre.NewHTTPError(409)
|
return fibre.NewHTTPError(409, ret.Detail)
|
||||||
|
case "ERR_PE":
|
||||||
|
return fibre.NewHTTPError(403, ret.Detail)
|
||||||
|
case "ERR_FD":
|
||||||
|
return fibre.NewHTTPError(422, ret.Detail)
|
||||||
|
case "ERR_IX":
|
||||||
|
return fibre.NewHTTPError(422, ret.Detail)
|
||||||
default:
|
default:
|
||||||
return fibre.NewHTTPError(400)
|
return fibre.NewHTTPError(400, ret.Detail)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -110,9 +118,15 @@ func OutputRest(c *fibre.Context, t string, d Display, m Method, res []*db.Respo
|
||||||
case "ERR_DB":
|
case "ERR_DB":
|
||||||
return fibre.NewHTTPError(503)
|
return fibre.NewHTTPError(503)
|
||||||
case "ERR_KV":
|
case "ERR_KV":
|
||||||
return fibre.NewHTTPError(409)
|
return fibre.NewHTTPError(409, ret.Detail)
|
||||||
|
case "ERR_PE":
|
||||||
|
return fibre.NewHTTPError(403, ret.Detail)
|
||||||
|
case "ERR_FD":
|
||||||
|
return fibre.NewHTTPError(422, ret.Detail)
|
||||||
|
case "ERR_IX":
|
||||||
|
return fibre.NewHTTPError(422, ret.Detail)
|
||||||
default:
|
default:
|
||||||
return fibre.NewHTTPError(400)
|
return fibre.NewHTTPError(400, ret.Detail)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(res[0].Result) == 0 {
|
if len(res[0].Result) == 0 {
|
||||||
|
@ -176,9 +190,15 @@ func OutputJson(c *fibre.Context, t string, d Display, m Method, res []*db.Respo
|
||||||
case "ERR_DB":
|
case "ERR_DB":
|
||||||
return fibre.NewHTTPError(503)
|
return fibre.NewHTTPError(503)
|
||||||
case "ERR_KV":
|
case "ERR_KV":
|
||||||
return fibre.NewHTTPError(409)
|
return fibre.NewHTTPError(409, ret.Detail)
|
||||||
|
case "ERR_PE":
|
||||||
|
return fibre.NewHTTPError(403, ret.Detail)
|
||||||
|
case "ERR_FD":
|
||||||
|
return fibre.NewHTTPError(422, ret.Detail)
|
||||||
|
case "ERR_IX":
|
||||||
|
return fibre.NewHTTPError(422, ret.Detail)
|
||||||
default:
|
default:
|
||||||
return fibre.NewHTTPError(400)
|
return fibre.NewHTTPError(400, ret.Detail)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(res[0].Result) == 0 {
|
if len(res[0].Result) == 0 {
|
||||||
|
|
Loading…
Reference in a new issue