Skip to content

Commit 86aa2a8

Browse files
authored
Merge pull request #16 from mlanin/bugfix/throwable
Use \Throwable instead of default \Exception
2 parents 5fbd782 + c61f60c commit 86aa2a8

12 files changed

+33
-43
lines changed

src/ApiException.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ abstract class ApiException extends IdException implements Jsonable, \JsonSerial
1313
protected $headers = [];
1414

1515
/**
16-
* @param int $statusCode
17-
* @param string $id
18-
* @param string $message
19-
* @param \Exception $previous
20-
* @param array $headers
16+
* @param int $statusCode
17+
* @param string $id
18+
* @param string $message
19+
* @param \Throwable|null $previous
20+
* @param array $headers
2121
*/
22-
public function __construct($statusCode = 0, $id = '', $message = '', \Exception $previous = null, array $headers = [])
22+
public function __construct($statusCode = 0, $id = '', $message = '', ?\Throwable $previous = null, array $headers = [])
2323
{
2424
$this->headers = $headers;
2525

src/BadRequestApiException.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
namespace Lanin\Laravel\ApiExceptions;
44

5-
use Exception;
65
use Lanin\Laravel\ApiExceptions\Contracts\DontReport;
76

87
class BadRequestApiException extends ApiException implements DontReport
98
{
109
/**
1110
* @param string $message
12-
* @param Exception $previous
11+
* @param \Throwable|null $previous
1312
*/
14-
public function __construct($message = '', Exception $previous = null)
13+
public function __construct($message = '', ?\Throwable $previous = null)
1514
{
1615
if (empty($message)) {
1716
$message = 'The server cannot process the request due to its malformed syntax.';

src/ConflictApiException.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
namespace Lanin\Laravel\ApiExceptions;
44

5-
use Exception;
65
use Lanin\Laravel\ApiExceptions\Contracts\DontReport;
76

87
class ConflictApiException extends ApiException implements DontReport
98
{
109
/**
1110
* @param string $message
12-
* @param Exception $previous
11+
* @param \Throwable $previous
1312
*/
14-
public function __construct($message = '', Exception $previous = null)
13+
public function __construct($message = '', ?\Throwable $previous = null)
1514
{
1615
if (empty($message)) {
1716
$message = 'Request could not be processed because of conflict.';

src/ExceptionHandlerTrait.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Lanin\Laravel\ApiExceptions;
44

5-
use Throwable;
65
use Illuminate\Auth\Access\AuthorizationException;
76
use Illuminate\Auth\AuthenticationException;
87
use Illuminate\Database\Eloquent\ModelNotFoundException;
@@ -16,11 +15,11 @@ trait ExceptionHandlerTrait
1615
* Report or log an exception.
1716
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
1817
*
19-
* @param Throwable $e
18+
* @param \Throwable $e
2019
* @return void
21-
* @throws Exception
20+
* @throws \Throwable
2221
*/
23-
public function report(Throwable $e)
22+
public function report(\Throwable $e)
2423
{
2524
parent::report($e instanceof ApiException ? $e->toReport() : $e);
2625
}
@@ -29,10 +28,10 @@ public function report(Throwable $e)
2928
* Render an exception into an HTTP response.
3029
*
3130
* @param \Illuminate\Http\Request $request
32-
* @param Throwable $e
31+
* @param \Throwable $e
3332
* @return \Illuminate\Http\Response
3433
*/
35-
public function render($request, Throwable $e)
34+
public function render($request, \Throwable $e)
3635
{
3736
$e = $this->resolveException($e);
3837

@@ -44,10 +43,10 @@ public function render($request, Throwable $e)
4443
/**
4544
* Define exception.
4645
*
47-
* @param Throwable $e
46+
* @param \Throwable $e
4847
* @return ApiException
4948
*/
50-
protected function resolveException(Throwable $e)
49+
protected function resolveException(\Throwable $e)
5150
{
5251
switch (true) {
5352
case $e instanceof ApiException:

src/ForbiddenApiException.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
namespace Lanin\Laravel\ApiExceptions;
44

5-
use Exception;
65
use Lanin\Laravel\ApiExceptions\Contracts\DontReport;
76

87
class ForbiddenApiException extends ApiException implements DontReport
98
{
109
/**
1110
* @param string $message
12-
* @param Exception $previous
11+
* @param \Throwable|null $previous
1312
*/
14-
public function __construct($message = '', Exception $previous = null)
13+
public function __construct($message = '', ?\Throwable $previous = null)
1514
{
1615
if (empty($message)) {
1716
$message = "You don't have permissions to perform this request.";

src/IdException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ class IdException extends \RuntimeException
99
/**
1010
* @param string $id
1111
* @param string $message
12-
* @param \Exception $previous
12+
* @param \Throwable|null $previous
1313
* @param int $code
1414
*/
15-
public function __construct($id = '', $message = '', \Exception $previous = null, $code = 0)
15+
public function __construct($id = '', $message = '', ?\Throwable $previous = null, $code = 0)
1616
{
1717
$this->id = $id;
1818

src/InternalServerErrorApiException.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22

33
namespace Lanin\Laravel\ApiExceptions;
44

5-
use Exception;
65
use Lanin\Laravel\ApiExceptions\Contracts\ShowsPrevious;
76
use Lanin\Laravel\ApiExceptions\Contracts\ShowsTrace;
87

98
class InternalServerErrorApiException extends ApiException implements ShowsTrace, ShowsPrevious
109
{
1110
/**
1211
* @param string $message
13-
* @param Exception $previous
12+
* @param \Throwable|null $previous
1413
*/
15-
public function __construct($message = '', Exception $previous = null)
14+
public function __construct($message = '', ?\Throwable $previous = null)
1615
{
1716
if (empty($message)) {
1817
$message = 'The server encountered an internal error or misconfiguration and was unable to complete your request.';

src/MethodNotAllowedApiException.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
namespace Lanin\Laravel\ApiExceptions;
44

5-
use Exception;
65
use Lanin\Laravel\ApiExceptions\Contracts\DontReport;
76

87
class MethodNotAllowedApiException extends ApiException implements DontReport
98
{
109
/**
1110
* @param string $message
12-
* @param Exception $previous
11+
* @param \Throwable|null $previous
1312
*/
14-
public function __construct($message = '', Exception $previous = null)
13+
public function __construct($message = '', ?\Throwable $previous = null)
1514
{
1615
if (empty($message)) {
1716
$message = 'A request was made of a resource using a request method not supported by that resource.';

src/NotFoundApiException.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
namespace Lanin\Laravel\ApiExceptions;
44

5-
use Exception;
65
use Lanin\Laravel\ApiExceptions\Contracts\DontReport;
76

87
class NotFoundApiException extends ApiException implements DontReport
98
{
109
/**
1110
* @param string $message
12-
* @param Exception $previous
11+
* @param \Throwable|null $previous
1312
*/
14-
public function __construct($message = '', Exception $previous = null)
13+
public function __construct($message = '', ?\Throwable $previous = null)
1514
{
1615
if (empty($message)) {
1716
$message = 'Requested object not found.';

src/TooManyRequestsApiException.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Lanin\Laravel\ApiExceptions;
44

5-
use Exception;
65
use Lanin\Laravel\ApiExceptions\Contracts\DontReport;
76

87
class TooManyRequestsApiException extends ApiException implements DontReport
@@ -16,9 +15,9 @@ class TooManyRequestsApiException extends ApiException implements DontReport
1615
* @param int|null $retryAfter
1716
* @param array $headers
1817
* @param string $message
19-
* @param Exception $previous
18+
* @param \Throwable|null $previous
2019
*/
21-
public function __construct($retryAfter = null, $headers = [], $message = '', Exception $previous = null)
20+
public function __construct($retryAfter = null, $headers = [], $message = '', ?\Throwable $previous = null)
2221
{
2322
$this->retryAfter = $retryAfter;
2423

0 commit comments

Comments
 (0)