errors only have an exposed Inner property if the error was generated by another library

This commit is contained in:
Dave Grijalva 2016-06-15 16:42:50 -07:00
parent 2ed748cd9c
commit 5fbf45924d
1 changed files with 7 additions and 2 deletions

View File

@ -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()