Fix RequestError.Is
This commit is contained in:
parent
fece6ec681
commit
e863120b51
2 changed files with 5 additions and 3 deletions
|
@ -45,9 +45,9 @@ func (re RequestError) Error() string {
|
|||
}
|
||||
|
||||
func (re RequestError) Is(other error) bool {
|
||||
otherRe, ok := other.(RequestError)
|
||||
if !ok {
|
||||
return errors.Is(*re.HTTP, other)
|
||||
var otherRe RequestError
|
||||
if !errors.As(other, &otherRe) {
|
||||
return re.HTTP != nil && errors.Is(*re.HTTP, other)
|
||||
}
|
||||
return otherRe.Data.GetType() == re.Data.GetType() &&
|
||||
otherRe.Data.GetMessage() == re.Data.GetMessage()
|
||||
|
|
|
@ -2,6 +2,7 @@ package events_test
|
|||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -18,6 +19,7 @@ func TestRequestError_Is(t *testing.T) {
|
|||
err := pblite.Unmarshal(dat, &errResp)
|
||||
require.NoError(t, err)
|
||||
assert.ErrorIs(t, events.RequestError{Data: &errResp}, events.ErrRequestedEntityNotFound)
|
||||
assert.ErrorIs(t, events.RequestError{Data: &errResp}, fmt.Errorf("meow: %w", events.ErrRequestedEntityNotFound))
|
||||
assert.NotErrorIs(t, events.RequestError{Data: &errResp}, events.RequestError{
|
||||
Data: &gmproto.ErrorResponse{
|
||||
Type: 5,
|
||||
|
|
Loading…
Reference in a new issue