From 03ad2b6636244621082bd60fd071bf64f6d25be3 Mon Sep 17 00:00:00 2001 From: Tony Chen Date: Tue, 1 Mar 2022 12:04:57 +0800 Subject: [PATCH] fix: error code judgment (#1849) * fix error code judgment * fix errors test --- errors/errors.go | 2 +- errors/errors_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/errors/errors.go b/errors/errors.go index dd4850cba..4126d61be 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -38,7 +38,7 @@ func (e *Error) GRPCStatus() *status.Status { // Is matches each error in the chain with the target value. func (e *Error) Is(err error) bool { if se := new(Error); errors.As(err, &se) { - return se.Reason == e.Reason + return se.Code == e.Code && se.Reason == e.Reason } return false } diff --git a/errors/errors_test.go b/errors/errors_test.go index 8fae9eb54..4abf1cb0a 100644 --- a/errors/errors_test.go +++ b/errors/errors_test.go @@ -76,7 +76,7 @@ func TestIs(t *testing.T) { }{ { name: "true", - e: &Error{Reason: "test"}, + e: &Error{Code: 404, Reason: "test"}, err: New(http.StatusNotFound, "test", ""), want: true, },