Exceptions raised during controller creation result in a "200" response being sent to the client.
obbc opened this issue · comments
If an exception is raised when constructing a controller then the response returned to the client contains a "200" status code, rather than a status code from the error range ("500" seems to be the most appropriate in this case).
Additionally, if running under IIS, the body of the response contains an embedded HTTP response, rather than just the exception message, e.g.:
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Server: Microsoft-IIS/10.0
Server: DelphiMVCFramework 3.1.0 lithium (beta)
Date: Tue, 07 Aug 2018 10:43:21 GMT
Content-Length: 216HTTP/1.1 200 OK
Server: Microsoft-IIS/10.0
Date: Tue, 07 Aug 2018 10:43:21 GMT
Connection: close
Server: DelphiMVCFramework 3.1.0 lithium (beta)
Content-Type: text/html; charset=UTF-8
Content-Length: 5Exception message.
This seems to be due to both flushing the default response when "LContext" is freed at the end of "TMVCEngine.ExecuteAction" and calling "SendResponse" from the exception handler inside "TMVCEngine.OnBeforeDispatch".
Which version?
Update: OK; I saw the version in the server signature.
Can you try with 3.0.0 hydrogen?
Hi,
The issue also affects hydrogen. Sorry I wasn't clearer with the initial report, that was a rookie mistake on my part!
Can you provide a sample project? The constructor is not virtual in TMVCController
, so how you can raise an exception in your controller? Are you using the delegates?
I was using delegates in my original project (for integration with the Spring4D DI container), but the problem can also be demonstrated by overriding the "AfterConstruction" method (see attached project).
OK, we'll fix it in 3.1 helium