From 0615896c0e3c432691e53aec0dd81efee6107256 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Wed, 9 May 2018 22:51:23 +0100 Subject: [PATCH] Add timeout errors to json output --- db/create_test.go | 2 +- db/delete_test.go | 2 +- db/executor.go | 2 ++ db/update_test.go | 2 +- util/show/show.go | 6 ++++++ 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/db/create_test.go b/db/create_test.go index 011c30f4..965c15b1 100644 --- a/db/create_test.go +++ b/db/create_test.go @@ -301,7 +301,7 @@ func TestCreate(t *testing.T) { So(res, ShouldHaveLength, 3) So(res[1].Result, ShouldHaveLength, 0) So(res[2].Result, ShouldHaveLength, 0) - So(res[1].Status, ShouldEqual, "ERR") + So(res[1].Status, ShouldEqual, "ERR_TO") So(res[1].Detail, ShouldEqual, "Query timeout of 1ms exceeded") }) diff --git a/db/delete_test.go b/db/delete_test.go index be7ac714..59d205ee 100644 --- a/db/delete_test.go +++ b/db/delete_test.go @@ -149,7 +149,7 @@ func TestDelete(t *testing.T) { So(res, ShouldHaveLength, 3) So(res[1].Result, ShouldHaveLength, 0) So(res[2].Result, ShouldHaveLength, 0) - So(res[1].Status, ShouldEqual, "ERR") + So(res[1].Status, ShouldEqual, "ERR_TO") So(res[1].Detail, ShouldEqual, "Query timeout of 1ns exceeded") }) diff --git a/db/executor.go b/db/executor.go index 7e294b4c..f6f58881 100644 --- a/db/executor.go +++ b/db/executor.go @@ -542,6 +542,8 @@ func status(e error) (s string) { return "ERR_FD" case *IndexError: return "ERR_IX" + case *TimerError: + return "ERR_TO" case error: return "ERR" } diff --git a/db/update_test.go b/db/update_test.go index d69f87b2..f1652424 100644 --- a/db/update_test.go +++ b/db/update_test.go @@ -295,7 +295,7 @@ func TestUpdate(t *testing.T) { So(res, ShouldHaveLength, 3) So(res[1].Result, ShouldHaveLength, 0) So(res[2].Result, ShouldHaveLength, 0) - So(res[1].Status, ShouldEqual, "ERR") + So(res[1].Status, ShouldEqual, "ERR_TO") So(res[1].Detail, ShouldEqual, "Query timeout of 1ms exceeded") }) diff --git a/util/show/show.go b/util/show/show.go index a3e0a6c0..6a42ffde 100644 --- a/util/show/show.go +++ b/util/show/show.go @@ -99,6 +99,8 @@ func OutputBase(c *fibre.Context, t string, d Display, m Method, res []*db.Respo return fibre.NewHTTPError(422, ret.Detail) case "ERR_IX": return fibre.NewHTTPError(422, ret.Detail) + case "ERR_TO": + return fibre.NewHTTPError(504, ret.Detail) default: return fibre.NewHTTPError(400, ret.Detail) } @@ -125,6 +127,8 @@ func OutputRest(c *fibre.Context, t string, d Display, m Method, res []*db.Respo return fibre.NewHTTPError(422, ret.Detail) case "ERR_IX": return fibre.NewHTTPError(422, ret.Detail) + case "ERR_TO": + return fibre.NewHTTPError(504, ret.Detail) default: return fibre.NewHTTPError(400, ret.Detail) } @@ -197,6 +201,8 @@ func OutputJson(c *fibre.Context, t string, d Display, m Method, res []*db.Respo return fibre.NewHTTPError(422, ret.Detail) case "ERR_IX": return fibre.NewHTTPError(422, ret.Detail) + case "ERR_TO": + return fibre.NewHTTPError(504, ret.Detail) default: return fibre.NewHTTPError(400, ret.Detail) }