Closed mrtnhwttktc closed 21 hours ago
Thanks @mrtnhwttktc - I can reproduce this. It looks like the 404 is being caught by the default 'not found' handler in the Lambda implementation, which is trying to handle a request that's already been responded to. This'll need a new release to fix, once we have one.
This should be fixed in release 4.0.4 (a delightful coincidence!)
I just tested v4.0.4 (nice) and confirmed the fix works as intended! Thank you for fixing this so quickly! Closing this issue.
When using Imposter on AWS Lambda, creating a mock of an endpoint that should return a status code 404 results in a status code 500 instead.
Expected Behavior
The endpoint should return a 404 status code with the specified JSON content.
Actual Behavior
The endpoint returns a 500 status code with the following response:
Steps to Reproduce
demo-config.yaml
:demo.yaml
:Environment Details
Logs
Looking at the logs, it seems that Imposter was initially able to generate the mock with a 404 status code, but after closing/ending the response encountered an error and then sent a status code 500 instead.
DEBUG logs:
I also have logs with trace enabled but couldn't include them because they are too long but if needed I can send them, let me know.
I looked around in the code a little and found this function which seems to be called and causing the issue:
It seems to match the warning I am seeing in the logs right after generating the correct 404 status code mock.
From the comment, it looks like the status code 404 is mistakenly seen as not originating from the mock engine? Calling
responseService.sendNotFoundResponse(httpExchange)
then triggers theIllegalStateException
inHttpResponse
because the response should already be marked as finished.Looking at the logs the RequestId seems to be set so it shouldn't be null, so I was thinking that the
response.sendNotFoundResponse
fromResourceUtil.RC_SEND_NOT_FOUND_RESPONSE
is incorrectly set to true somewhere along the way.I looked around in the codebase but do not know kotlin/java well so I had trouble finding exactly what is happening.
I also tested using the imposter CLI and the error does not happen while using the same config file so I think the issue is exclusive to AWS Lambda.
Let me know if there is any other details I could provide. I am new to Kotlin but I will be trying to build it with some changes to see if I can find out what is causing the issue, if I am successful and find anything relevant I will update this issue.