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).

@codecov
Copy link

codecov bot commented Feb 10, 2026

Codecov Report

❌ Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.89%. Comparing base (48f25a6) to head (a16859c).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
httperror.go 77.77% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2892      +/-   ##
==========================================
- Coverage   92.92%   92.89%   -0.04%     
==========================================
  Files          43       43              
  Lines        4480     4489       +9     
==========================================
+ Hits         4163     4170       +7     
- Misses        197      198       +1     
- Partials      120      121       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aldas
Copy link
Contributor

aldas commented Feb 10, 2026

This is a good idea. I have to research a bit this. I know that Is Unwrap etc are recursive and our HTTPError contains also wrapped error field. I do not want to merge things that I am not fully sure. It is easy to add new things but hard to remove them.

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.

2 participants