From 465274cd2175a05c8ce22e27f9c08315129aae0a Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Mon, 15 May 2017 16:28:47 +0200 Subject: [PATCH] server-info: Change Error type to string (#4346) Golang std error type doesn't marshal/unmarshal with json. So errors are not actually being sent when a client calls ServerInfo() API. --- cmd/admin-handlers.go | 8 ++++---- cmd/admin-handlers_test.go | 2 +- pkg/madmin/info-commands.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/admin-handlers.go b/cmd/admin-handlers.go index 8396e4e6b..3d4f34852 100644 --- a/cmd/admin-handlers.go +++ b/cmd/admin-handlers.go @@ -241,9 +241,9 @@ type ServerInfoData struct { // ServerInfo holds server information result of one node type ServerInfo struct { - Error error - Addr string - Data *ServerInfoData + Error string `json:"error"` + Addr string `json:"addr"` + Data *ServerInfoData `json:"data"` } // ServerInfoHandler - GET /?info @@ -276,7 +276,7 @@ func (adminAPI adminAPIHandlers) ServerInfoHandler(w http.ResponseWriter, r *htt serverInfoData, err := peer.cmdRunner.ServerInfoData() if err != nil { errorIf(err, "Unable to get server info from %s.", peer.addr) - reply[idx].Error = err + reply[idx].Error = err.Error() return } diff --git a/cmd/admin-handlers_test.go b/cmd/admin-handlers_test.go index a8d984f9e..68ccdd80e 100644 --- a/cmd/admin-handlers_test.go +++ b/cmd/admin-handlers_test.go @@ -1314,7 +1314,7 @@ func TestAdminServerInfo(t *testing.T) { if len(serverInfo.Addr) == 0 { t.Error("Expected server address to be non empty") } - if serverInfo.Error != nil { + if serverInfo.Error != "" { t.Errorf("Unexpected error = %v\n", serverInfo.Error) } if serverInfo.Data.StorageInfo.Free == 0 { diff --git a/pkg/madmin/info-commands.go b/pkg/madmin/info-commands.go index 01dcff234..f6f93265e 100644 --- a/pkg/madmin/info-commands.go +++ b/pkg/madmin/info-commands.go @@ -84,7 +84,7 @@ type ServerInfoData struct { // ServerInfo holds server information result of one node type ServerInfo struct { - Error error `json:"error"` + Error string `json:"error"` Addr string `json:"addr"` Data *ServerInfoData `json:"data"` }