diff --git a/exception.go b/exception.go index e4aacf4..09734c9 100644 --- a/exception.go +++ b/exception.go @@ -31,6 +31,9 @@ func (ex *custom) With(innerErr ...error) Custom { } func (ex *custom) IsSameAs(err error) bool { + if err == nil { + return false + } return strings.HasPrefix(err.Error(), fmt.Sprintf("[%s]:", ex.message)) } diff --git a/exception_test.go b/exception_test.go index eae5ae5..fb7d94c 100644 --- a/exception_test.go +++ b/exception_test.go @@ -46,6 +46,7 @@ func (suite *CustomExceptionTestSuite) TestShouldCompareExceptions() { suite.False(NotFoundException.IsSameAs(InvalidArgumentException)) suite.False(NotFoundException.IsSameAs(customErr)) suite.False(InvalidArgumentException.IsSameAs(customErr)) + suite.False(InvalidArgumentException.IsSameAs(nil)) } func TestCustomExceptionTestSuite(t *testing.T) {