Skip to content

fix(DefaultHTTPErrorHandler): return error message when message is an error#2456

Merged
aldas merged 4 commits into
labstack:masterfrom
gnuletik:master
May 29, 2023
Merged

fix(DefaultHTTPErrorHandler): return error message when message is an error#2456
aldas merged 4 commits into
labstack:masterfrom
gnuletik:master

Conversation

@gnuletik

Copy link
Copy Markdown
Contributor

The current behavior when returning a go error from a echo handler like this:

return echo.NewHTTPError(status.BadRequest, errors.New("error in httperror"))

Is that echo returns an empty JSON object {}.

See the failing test result, without the fix:

    echo_test.go:1356:
        	Error Trace:	/~/echo/echo_test.go:1356
        	Error:      	Not equal:
        	            	expected: "{\"message\":\"error in httperror\"}\n"
        	            	actual  : "{}\n"

        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1,2 +1,2 @@
        	            	-{"message":"error in httperror"}
        	            	+{}

        	Test:       	TestDefaultHTTPErrorHandler

@codecov

codecov Bot commented May 26, 2023

Copy link
Copy Markdown

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (8e425c0) 92.85% compared to head (e7e0db9) 92.86%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2456   +/-   ##
=======================================
  Coverage   92.85%   92.86%           
=======================================
  Files          39       39           
  Lines        4563     4568    +5     
=======================================
+ Hits         4237     4242    +5     
  Misses        237      237           
  Partials       89       89           
Impacted Files Coverage Δ
echo.go 95.52% <100.00%> (+0.05%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment thread echo.go
Comment thread echo_test.go Outdated
@gnuletik gnuletik requested a review from aldas May 29, 2023 12:37

@aldas aldas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aldas aldas merged commit fbfe216 into labstack:master May 29, 2023
@aldas

aldas commented May 29, 2023

Copy link
Copy Markdown
Contributor

Thank @gnuletik

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