Fix RequestError.Is

This commit is contained in:
Tulir Asokan 2023-09-04 14:31:59 +03:00
parent fece6ec681
commit e863120b51
2 changed files with 5 additions and 3 deletions

View file

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

View file

@ -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,