Skip to content

Commit c11ef1a

Browse files
author
Maxim Lanin
committed
Remove middleware
1 parent c42b96a commit c11ef1a

File tree

4 files changed

+12
-63
lines changed

4 files changed

+12
-63
lines changed

README.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ The goal of this package is to provide you with a set of most common exceptions
99
* Handles exceptions report to logs.
1010
* Overwrites default Validator to make validation errors more verbose.
1111
* Has a FormRequest that to handle validation errors and pass them to ApiExceptions layer.
12-
* Has middleware to catch all system errors such us `RuntimeExceptions` or `ModelNotFoundException` to handle them and threat as normal ApiExceptions.
1312

1413
## Installation
1514

@@ -62,7 +61,7 @@ Also it can have `meta` attribute when there is additional info. For example for
6261
}
6362
```
6463

65-
For `ValidationApiException`, meta attribute has `errors` object that contains validations errors.
64+
For `ValidationApiException`, meta attribute has `errors` object that contains validations errors.
6665
Every attribute of this object is a name of a request parameter to validate to and value is an array of errors with description.
6766

6867
### Handler
@@ -90,15 +89,10 @@ class Handler extends LaravelExceptionHandle
9089
### FormRequest
9190

9291
To use FormRequest extend all your Request classes with `\Lanin\Laravel\ApiExceptions\Support\Request`.
93-
It will automatically support validation errors and pass them to the output.
92+
It will automatically support validation errors and pass them to the output.
9493

9594
It also has a very handy helper method `validatedOnly()` that returns from request only those items that are registered in rules method.
9695

97-
### RuntimeExceptionsHandler
98-
99-
Also you can catch all system exceptions using `\Lanin\Laravel\ApiExceptions\Support\RuntimeExceptionsHandler`.
100-
Just import it to your `Http\Kernel` $middleware array, and that's it.
101-
10296
## Contributing
10397

10498
Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.

src/LaravelExceptionHandler.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,24 @@ public function render($request, Exception $e)
5454
{
5555
switch (true) {
5656
case $e instanceof ApiException:
57-
$response = response()->json($e, $e->getCode(), $e->getHeaders());
5857
break;
5958
case $e instanceof AuthorizationException:
6059
$e = new UnauthorizedApiException('', $e);
61-
$response = response()->json($e, $e->getCode());
60+
break;
61+
case $e instanceof MethodNotAllowedHttpException:
62+
$e = new MethodNotAllowedApiException('', $e);
6263
break;
6364
case $e instanceof ModelNotFoundException:
6465
case $e instanceof NotFoundHttpException:
6566
$e = new NotFoundApiException();
66-
$response = response()->json($e, $e->getCode());
6767
break;
6868
default:
6969
$e = new InternalServerErrorApiException('', $e);
70-
$response = response()->json($e, $e->getCode());
7170
break;
7271
}
7372

73+
$response = response()->json($e, $e->getCode(), $e->getHeaders());
74+
7475
return $response;
7576
}
7677
}

src/LumenExceptionHandler.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,24 @@ public function render($request, Exception $e)
5858
{
5959
switch (true) {
6060
case $e instanceof ApiException:
61-
$response = response()->json($e, $e->getCode(), $e->getHeaders());
6261
break;
6362
case $e instanceof AuthorizationException:
6463
$e = new UnauthorizedApiException('', $e);
65-
$response = response()->json($e, $e->getCode());
64+
break;
65+
case $e instanceof MethodNotAllowedHttpException:
66+
$e = new MethodNotAllowedApiException('', $e);
6667
break;
6768
case $e instanceof ModelNotFoundException:
6869
case $e instanceof NotFoundHttpException:
6970
$e = new NotFoundApiException();
70-
$response = response()->json($e, $e->getCode());
7171
break;
7272
default:
7373
$e = new InternalServerErrorApiException('', $e);
74-
$response = response()->json($e, $e->getCode());
7574
break;
7675
}
7776

77+
$response = response()->json($e, $e->getCode(), $e->getHeaders());
78+
7879
return $response;
7980
}
8081
}

src/Support/RuntimeExceptionsHandler.php

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)