Merge pull request #726 from duglin/FixError
Make Error.Error() return the post-arg-substitution Message
This commit is contained in:
commit
f93d70ee9e
2 changed files with 6 additions and 1 deletions
|
@ -106,7 +106,7 @@ func (e Error) ErrorCode() ErrorCode {
|
||||||
func (e Error) Error() string {
|
func (e Error) Error() string {
|
||||||
return fmt.Sprintf("%s: %s",
|
return fmt.Sprintf("%s: %s",
|
||||||
strings.ToLower(strings.Replace(e.Code.String(), "_", " ", -1)),
|
strings.ToLower(strings.Replace(e.Code.String(), "_", " ", -1)),
|
||||||
e.Code.Message())
|
e.Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithDetail will return a new Error, based on the current one, but with
|
// WithDetail will return a new Error, based on the current one, but with
|
||||||
|
|
|
@ -126,6 +126,11 @@ func TestErrorsManagement(t *testing.T) {
|
||||||
t.Fatalf("Wrong msg, got:\n%q\n\nexpected:\n%q", e1.Message, exp1)
|
t.Fatalf("Wrong msg, got:\n%q\n\nexpected:\n%q", e1.Message, exp1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exp1 = "test3: " + exp1
|
||||||
|
if e1.Error() != exp1 {
|
||||||
|
t.Fatalf("Error() didn't return the right string, got:%s\nexpected:%s", e1.Error(), exp1)
|
||||||
|
}
|
||||||
|
|
||||||
// Test again with a single value this time
|
// Test again with a single value this time
|
||||||
errs = Errors{ErrorCodeUnknown}
|
errs = Errors{ErrorCodeUnknown}
|
||||||
expectedJSON = "{\"errors\":[{\"code\":\"UNKNOWN\",\"message\":\"unknown error\"}]}"
|
expectedJSON = "{\"errors\":[{\"code\":\"UNKNOWN\",\"message\":\"unknown error\"}]}"
|
||||||
|
|
Loading…
Reference in a new issue