-
-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTP status code != API Problem status #6
Comments
@weierophinney can you look at this issue? It's looks seriously Originally posted by @snapshotpl at zfcampus/zf-api-problem#27 (comment) |
I totally agree that ZF Api Problem should not interpret exception codes as http status codes. Exception codes can mean anything. For example, \PDOException uses code to transport the SQLSTATE error code. I therefore propose that we extend ProblemExceptionInterface with a new method getHttpStatusCode() which returns an integer value to use. Otherwise we just assume 500. @weierophinney could you please give feedback? If you want, i could create a pull request. Originally posted by @BreiteSeite at zfcampus/zf-api-problem#27 (comment) |
@BreiteSeite makes sense; feel free to start a PR! :) Originally posted by @weierophinney at zfcampus/zf-api-problem#27 (comment) |
How is the status of this issue or it's pull request? Originally posted by @FrankGiesecke at zfcampus/zf-api-problem#27 (comment) |
I think api-problem should interpret the exception code only if the exception implements the Furthermore, IMHO, only codes in 4xx and 5xx ranges should be considered "problems". throw new \Exception('Error', 302); will produce a For this reason, I had to patch temporary some projects. Currently, I attached a listener to intercept exceptions: use Zend\Mvc\MvcEvent;
use ZF\ApiProblem\Exception\ProblemExceptionInterface;
class UnhandledExceptionListener
{
public function __invoke(MvcEvent $e)
{
if (!$e->isError()) {
return;
}
$exception = $e->getParam('exception');
if ($exception
&& !$exception instanceof ProblemExceptionInterface
&& $exception instanceof \Exception
&& ($exception->getCode() < 400 || $exception->getCode() > 599)
) {
$internalServerErrorEx = new InternalServerErrorException($exception);
$e->setParam('exception', $internalServerErrorEx);
}
}
}
class InternalServerErrorException extends \Exception
{
public function __construct($previous)
{
parent::__construct('Internal Server Error', 500, $previous);
}
} A possibile solution to avoid BCs in 1.0.x is to check the code ranges only. The Originally posted by @leogr at zfcampus/zf-api-problem#27 (comment) |
@weierophinney any news? Originally posted by @leogr at zfcampus/zf-api-problem#27 (comment) |
When I throw exception in resource:
I get:
Apigility documentation says (https://apigility.org/documentation/api-primer/error-reporting):
And API problem documentation (https://tools.ietf.org/html/draft-nottingham-http-problem-06):
BTW Response after
looks funny :-)
Originally posted by @snapshotpl at zfcampus/zf-api-problem#27
The text was updated successfully, but these errors were encountered: