samsonasik / ErrorHeroModule

:gem: A Hero for your Zend Framework/Laminas, and Expressive/Mezzio application to log ( DB and Mail ) and handle php errors & exceptions during Mvc process/between request and response
MIT License
50 stars 7 forks source link

If the Ajax message is used, the HTTP response code shouldn't be 200 #5

Closed parktrip closed 7 years ago

parktrip commented 7 years ago

Dear samsonasik,

first thank you for your useful module.

I have just noticed something that bothered me a bit: if your module catches an error while doing an ajax call (the '$request->isXmlHttpRequest()' is a bit restricted as I would like to use it performing json calls but that's another story :) ), the ajax message set in the config is displayed as expected but with an 200 HTTP code. That's make difficult if not impossible to catch this failure at client side level. Is there any way to change this and set a different HTTP code (500 would be the one IMO) ? And set as well a proper Content-type header (text/html at the moment which is not correct).

Regards,

samsonasik commented 7 years ago

@parktrip Thank you for using it. Yes, it should be 500 status code. For XmlHttpRequest, the content-type = 'application/json' is not a must, it can be text/html also depends on how we set in the message in the config. I've added check content for it.

Released ErrorHeroModule 1.3.1 for it, enjoy ;)

parktrip commented 7 years ago

Thank you for your reactivity, I will have a look at it as soon as possible.