From 5fbf45924d057121148b8b962a213360beb022ec Mon Sep 17 00:00:00 2001 From: Dave Grijalva Date: Wed, 15 Jun 2016 16:42:50 -0700 Subject: [PATCH] errors only have an exposed Inner property if the error was generated by another library --- errors.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/errors.go b/errors.go index d4b183c..662df19 100644 --- a/errors.go +++ b/errors.go @@ -30,7 +30,7 @@ const ( // Helper for constructing a ValidationError with a string error message func NewValidationError(errorText string, errorFlags uint32) *ValidationError { return &ValidationError{ - Inner: errors.New(errorText), + text: errorText, Errors: errorFlags, } } @@ -39,11 +39,16 @@ func NewValidationError(errorText string, errorFlags uint32) *ValidationError { type ValidationError struct { Inner error // stores the error returned by external dependencies, i.e.: KeyFunc Errors uint32 // bitfield. see ValidationError... constants + text string // errors that do not have a valid error just have text } // Validation error is an error type func (e ValidationError) Error() string { - if e.Inner == nil { + if e.Inner != nil { + return e.Inner.Error() + } else if e.text != "" { + return e.text + } else { return "token is invalid" } return e.Inner.Error()