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

after hook prints response status 200 instead of 500 #561

Open
aitzkowi opened this issue Mar 5, 2016 · 6 comments
Open

after hook prints response status 200 instead of 500 #561

aitzkowi opened this issue Mar 5, 2016 · 6 comments

Comments

@aitzkowi
Copy link

aitzkowi commented Mar 5, 2016

I am using the after hook to print the response http status for each API call.

after() {
logger.info("request {} {} returned with status code {}", request.getMethod, request.getRequestURL, response.getStatus.toString)
}

When a method returns an error code with halt, the status code is printed correctly, but when the method return a status code in the last line (without halt), the status code which will be printed will always be 200, regardless of real status returned.

For example:

halt(InternalServerError("DB error")) //this will cause status 500 to be printed in the 'after' hook

InternalServerError("an unknown error occurred") //this will cause status 200 to be printed in the 'after' hook, although 500 is actually returned

scalatra 2.3

@olafleur
Copy link

olafleur commented Mar 9, 2016

I'm using 2.4.0 and I always have the value 0 in response.getStatus. Is that normal?

@dvgica
Copy link

dvgica commented May 5, 2016

I am seeing something similar on 2.4, although I'm wondering if #148 is the real problem in my case.

@poslegm
Copy link

poslegm commented Aug 14, 2016

Status code sets in renderPipeline method (calling in renderResponse).

Function in after hook executes before calling renderResponse method. See executeRoutes in ScalatraBase.scala.
But calling halt method sets status code by himself.

@aitzkowi
Copy link
Author

so then maybe the "after" hook should be called after "renderResponse"

@david-patterson-socure
Copy link

I'm assuming this is expected behavior? I've run into this problem as well.
Is the correct method to hook into renderPipeline in order to get the correct response?

@takezoe
Copy link
Member

takezoe commented May 16, 2022

Changing after as being called after renderResponse will break the existing applications that modify the response in after while changing the timing to set the response status could be considered. However, I think using ServletFilter is better to capture responses.

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

6 participants