These are chat archives for gin-gonic/gin

21st
Feb 2017
Depado
@Depado
Feb 21 2017 15:42
Hey people :)
I'm having trouble understanding how to handle errors in context. Especially the ones coming from Bind and BindJSON
Andrey Nering
@andreynering
Feb 21 2017 15:48

I don't know why but Gin writes status header automatically if there's an error on bind:
https://github.com/gin-gonic/gin/blob/master/context.go#L333

There's a lot of issues of people having trouble with that.
IMHO that should be changed

Depado
@Depado
Feb 21 2017 15:49
Yeah I noticed that too. But that's ok, this endpoint is supposed to always send back JSON, so I set the header early in the handler.
Andrey Nering
@andreynering
Feb 21 2017 15:50
@Depado That should work, but sounds like a workaround for me.
I think I will send a PR for that
Depado
@Depado
Feb 21 2017 15:51
It's more about formatting the response when there are errors on Bind so the user knows which fields failed.
When two required fields failed, the errors are separated by \n which is not frankly user-friendly.
And yeah that header thing is kind of a workaround.
(I opened an issue before remembering Gitter was a thing : #815 )