While API development I tried to guess the response status code of requests in a error handler. In most of the known frameworks in the PHP universe there is an error handler, where I get a Throwable
and there is a Throwable::getCode()
(documentation).
From my point of view this code
is more an identifier, than a status code. My best practice is using the current timestamp as code
, so I can find the corresponding place in my source code very fast. If I need a return status code I would extend the exception and add a statusCode
property.
After a research I saw so many solutions, where developers use the code
as return status code. So I am interested in a something like a default PHP exception mapper to status code without using the existing code as status code or at least a best practice to do so. Is there a open source solution or am I on the wrong path?