Improve command-line client error output (#122)

Motivation: The output when an error occurs shows an integer error code,
which isn't very helpful. And in the case of an error when creating a
resource, you also get a redundant log message from the controller
client.

Modifications:
* the controller client no longer logs errors
* the generated String() allows for the enum name to be displayed in the
  error output
* each errorCode enum member has a hand-generated description
* the format of the error message from the CLI client was modified to
  display the error description with the error message

Related to #112
This commit is contained in:
Toby Crawley
2017-02-16 13:58:59 -08:00
committed by Soam Vasani
parent eae5150bff
commit ab6e2e8021
4 changed files with 50 additions and 35 deletions
+10 -2
View File
@@ -23,8 +23,8 @@ import (
"strings"
)
func (e Error) Error() string {
return fmt.Sprintf("(Error %v) %v", e.Code, e.Message)
func (err Error) Error() string {
return fmt.Sprintf("%v - %v", err.Description(), err.Message)
}
func MakeError(code int, msg string) Error {
@@ -90,3 +90,11 @@ func GetHTTPError(err error) (int, string) {
}
return code, msg
}
func (err Error) Description() string {
idx := int(err.Code)
if idx < 0 || idx > len(errorDescriptions)-1 {
return ""
}
return errorDescriptions[idx]
}