From 385b2d20f3a8113de6799af0ca923691ef64b801 Mon Sep 17 00:00:00 2001 From: Maciej Wereski Date: Thu, 9 Nov 2017 16:09:09 +0100 Subject: [PATCH] Make ServerError implement error interface Change-Id: Ie804197ca5b777ad6afd2c01d55a853ae8c287ee Signed-off-by: Maciej Wereski --- http/error.go | 5 +++++ http/error_test.go | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/http/error.go b/http/error.go index 4f48c85..4771f1b 100644 --- a/http/error.go +++ b/http/error.go @@ -94,3 +94,8 @@ func NewServerError(err error, details ...string) (ret *ServerError) { return } + +// Error is implementation of error interface (it returns error string). +func (err *ServerError) Error() string { + return err.Err +} diff --git a/http/error_test.go b/http/error_test.go index 9940831..4f2e19d 100644 --- a/http/error_test.go +++ b/http/error_test.go @@ -63,3 +63,9 @@ func TestNewServerError(t *testing.T) { assert.Equal(notFound, NewServerError(NotFoundError("Fern Flower"))) assert.Nil(NewServerError(nil)) } + +func TestError(t *testing.T) { + assert := assert.New(t) + err := NewServerError(errors.New("foo")) + assert.Equal(err.Err, err.Error()) +} -- 2.7.4