Skip to content

Conversation

@suwakei
Copy link

@suwakei suwakei commented Feb 9, 2026

Overview

Implemented the Is method on the HTTPError struct, enabling error checking using errors.Is (particularly for comparing with sentinel errors).

Background

Starting with Go 1.13, errors.Is is recommended for error checking, but Echo's HTTPError did not previously implement the Is method. Echo's predefined errors (such as echo.ErrNotFound) are of the internal httpError type, while errors created with NewHTTPError are of type *HTTPError. Because these are distinct types in Go's type system, errors.Is(err, echo.ErrNotFound) would return false if err was of type *HTTPError, making intended error handling difficult. This change resolves the issue by adding logic that considers errors with matching status codes to be the same error.

Changes

  • httperror.go: Added an Is method to the HTTPError struct. When comparing against *HTTPError or *httpError, it compares the status code.
  • httperror_test.go: Added a test case for the Is method (TestHTTPError_Is).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant