fix: error code judgment (#1849)

* fix error code judgment

* fix errors test
pull/1855/head
Tony Chen 3 years ago committed by GitHub
parent 48d407cc9b
commit 03ad2b6636
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      errors/errors.go
  2. 2
      errors/errors_test.go

@ -38,7 +38,7 @@ func (e *Error) GRPCStatus() *status.Status {
// Is matches each error in the chain with the target value. // Is matches each error in the chain with the target value.
func (e *Error) Is(err error) bool { func (e *Error) Is(err error) bool {
if se := new(Error); errors.As(err, &se) { if se := new(Error); errors.As(err, &se) {
return se.Reason == e.Reason return se.Code == e.Code && se.Reason == e.Reason
} }
return false return false
} }

@ -76,7 +76,7 @@ func TestIs(t *testing.T) {
}{ }{
{ {
name: "true", name: "true",
e: &Error{Reason: "test"}, e: &Error{Code: 404, Reason: "test"},
err: New(http.StatusNotFound, "test", ""), err: New(http.StatusNotFound, "test", ""),
want: true, want: true,
}, },

Loading…
Cancel
Save