Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware should not write response body #5

Open
jdolitsky opened this issue May 1, 2018 · 2 comments
Open

Middleware should not write response body #5

jdolitsky opened this issue May 1, 2018 · 2 comments

Comments

@jdolitsky
Copy link

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
Copy link

I have the same problem.

@mymtw
Copy link

mymtw commented May 31, 2020

	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
	}

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

No branches or pull requests

3 participants