Middleware should not write response body
jdolitsky opened this issue · 2 comments
jdolitsky commented
Hi there, thanks for building this!
This middleware works as expected, the only issue I'm experiencing is that the request body is written as part of the middleware func:
ctx.String(http.StatusRequestEntityTooLarge, "request too large")
I'm trying to build an API where every response is JSON- even errors like this. What do you suggest? My response body ends up looking like:
request too large{"error":"HTTP request too large"}
Thanks in advance.
snowdream commented
I have the same problem.
mymtw commented
if err != nil {
s.Logger.Warn(err)
if c.IsAborted() {
return
}
c.AbortWithStatusJSON(http.StatusBadRequest, controllers.Error{
Code: fmt.Sprint(http.StatusBadRequest),
Message: err.Error(),
})
return
}