laminas-api-tools / api-tools

Laminas API Tools module for Laminas
https://api-tools.getlaminas.org/documentation
BSD 3-Clause "New" or "Revised" License
37 stars 19 forks source link

Getting Apigility to return a 500 response on a PHP Fatal Error #33

Open michalbundyra opened 4 years ago

michalbundyra commented 4 years ago

When PHP throws a fatal error, it spits out the HTML representation of error and it does so with a response code of 200.

Should these not be getting caught by Apigility and handled as 500 errors? Is there an extra step I need to take to achieve this, guidance on best practice?


Originally posted by @danbroooks at https://github.com/zfcampus/zf-apigility/issues/157

michalbundyra commented 4 years ago

Well I certainly agree that this shouldn't return a 200...Any input from regular contributors?


Originally posted by @spengilley at https://github.com/zfcampus/zf-apigility/issues/157#issuecomment-204994464

michalbundyra commented 4 years ago

Error handling is the responsibility of each application and does not fall into the scope of Apigility. Write your own error handler which returns a 500 ApiProblem (like) response.


Originally posted by @TomHAnderson at https://github.com/zfcampus/zf-apigility/issues/157#issuecomment-205030101

michalbundyra commented 4 years ago

Error handling is the responsibility of each application and does not fall into the scope of Apigility.

@TomHAnderson Normally I'd agree, but I seem to keep running into places where Apigility is interfering with the normal request lifecycle or places where it's returning 200 or 500 when an error is happening before it can ever hit my try/catch block.

Do you know of any resources that document the Apigility request lifecycle? I think this would be a helpful tool for debugging and something that the community could help contribute to the docs.


Originally posted by @jasonherndon at https://github.com/zfcampus/zf-apigility/issues/157#issuecomment-234587647

michalbundyra commented 4 years ago

If you would study the code and create the docs you're asking about I'm sure they could be included.


Originally posted by @TomHAnderson at https://github.com/zfcampus/zf-apigility/issues/157#issuecomment-234589137