dingo / dingo/api

Incorrect documentation for Internal Requests

Open
#1,421 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
9.4k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

According to the documentation, an InternalHttpException should be thrown when an error response (such as errorNotFound) is thrown during processing of an Internal Request; however, a Symphony\Component\HttpKernel\Exception\HttpException is thrown instead. This exception is more generic and lacks the getResponse() method shown in the docs.

From https://github.com/dingo/api/wiki/Internal-Requests:

> The package may also throw a Dingo\Api\Exception\InternalHttpException when an error response is returned. If you're using the response builder to return errors then you'll need to catch the thrown exception. The response will be available on the exception.

> public function show($id)
{
return $this->response->errorNotFound('Could not find the user.');
}
When internally calling this endpoint we'll need to catch the exception.

> try {
app('Dingo\Api\Dispatcher')->get('users/1');
} catch (Dingo\Api\Exception\InternalHttpException $e) {
// We can get the response here to check the status code of the error or response body.
$response = $e->getResponse();
}

Suspect line: https://github.com/dingo/api/blob/46cffad61942caa094dd876155e503b6819c5095/src/Http/Response/Factory.php#L173

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.