From 12c2ada0910552eb078d77403ccec08236374c0d Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Thu, 16 Nov 2017 19:24:46 +0000 Subject: [PATCH] Improve error messages on REST API queries --- util/show/show.go | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/util/show/show.go b/util/show/show.go index 75a5565e..a3e0a6c0 100644 --- a/util/show/show.go +++ b/util/show/show.go @@ -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 case *sql.EmptyError: return fibre.NewHTTPError(500) // Should not happen + case *fibre.HTTPError: + return err // Probably a timeout error } 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": return fibre.NewHTTPError(503) 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: - 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": return fibre.NewHTTPError(503) 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: - return fibre.NewHTTPError(400) + return fibre.NewHTTPError(400, ret.Detail) } 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": return fibre.NewHTTPError(503) 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: - return fibre.NewHTTPError(400) + return fibre.NewHTTPError(400, ret.Detail) } if len(res[0].Result) == 0 {