mschneider82 / problem

A go library that implements application/problem+json and application/problem+xml

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Http status in Echo context not set

eloo opened this issue · comments

Hi,
i'm using your library currently together with echo and i guess i've found an bug in the error handler example or in the writing code.

So when an error is handled/written to the response writer the http status is written to the response itself.
But sadly the status is not written to the echo context itself.
This results that http requests logs are always showing a status 200.

For example with the echo-logrus library or with this middleware

	router.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
		Format: "[${color.Blue('blue')}${time_custom}] ${protocol} ${method} uri=${uri} => ${status} ${latency_human}\n",
		Output: os.Stdout,
	}))

So either the status should be exported from a problem so we can set it in the handler on our own or it should be done in the prb.WriteTo.

What do you think?

best regards
eloo

I have looked to the example and docs and found out the example (was a PR) is wrong because we write to the http.ResponseWriter directly, instead of using the wrapped Writer. Can you please test the example with this line modified:

-            if _, err := prb.WriteTo(c.Response().Writer); err != nil {
+            if _, err := prb.WriteTo(c.Response()); err != nil {

Awesome!

Its working as expected with your change!

Thanks a lot

@eloo check out the newest v1.6.0 version it now has problem.Of() to auto-set the status title based on the statuscode! (see readme), it includes the fix in the README

thanks for the info..
looks great