diff --git a/README.md b/README.md index 0f8b327..33724f3 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ easily copy below code and paste in your `composer.json` easily copy below code and paste in your `composer.json` -> `require` section ``` -"liateam/api-exceptions": "1.0.0" +"liateam/api-exceptions": "^2.0" ``` run the command below in your project : @@ -52,15 +52,30 @@ run the command below in your project : $ composer update ``` +### lumen specific installation +if your project is lumen so you should copy `Liateam/api-exceptions/src/config/exceptions` to your `config` directory ! +*NOTE* : If you don't have `config` directory so create it ! + +then add below code in your `bootstrap/app.php` : +``` + $app->configure(exceptions); +``` + +### laravel specific installation +``` +$ php artisan vendor:publish --config="Liateam/api-exceptions/src/config/exceptions.php" +``` + + ## Usage overwrite `render` method of `App\Exceptions\Handler` like this : ``` - use Liateam\ApiException\Handlers\ApiException; + use Liateam\ApiExceptions\Handlers\ApiException; public function render($request, Throwable $exception) { - return ApiException::handle($exception); + return ApiException::handle($exception)->render(); } ``` diff --git a/src/Contracts/ApiException.php b/src/Contracts/ApiException.php index 5ac5f77..9fbd612 100644 --- a/src/Contracts/ApiException.php +++ b/src/Contracts/ApiException.php @@ -3,11 +3,11 @@ namespace Liateam\ApiExceptions\Contracts; use Exception; -use Liateam\ApiResponse\Contracts\ResponseContract; use \Throwable; use JetBrains\PhpStorm\Pure; use \Illuminate\Http\JsonResponse; use Liateam\ApiResponse\Responses\FailureResponse; +use Liateam\ApiResponse\Contracts\ResponseContract; abstract class ApiException extends Exception { diff --git a/src/Exceptions/CustomAuthenticationException.php b/src/Exceptions/CustomAuthenticationException.php index 1eeb192..cd1f97f 100644 --- a/src/Exceptions/CustomAuthenticationException.php +++ b/src/Exceptions/CustomAuthenticationException.php @@ -4,7 +4,7 @@ use Throwable; use Illuminate\Http\Response; -use Liateam\ApiException\Contracts\ApiException; +use Liateam\ApiExceptions\Contracts\ApiException; class CustomAuthenticationException extends ApiException { diff --git a/src/Exceptions/CustomDefaultException.php b/src/Exceptions/CustomDefaultException.php index d40e8d3..25416b7 100644 --- a/src/Exceptions/CustomDefaultException.php +++ b/src/Exceptions/CustomDefaultException.php @@ -3,7 +3,7 @@ namespace Liateam\ApiExceptions\Exceptions; use Illuminate\Http\Response; -use Liateam\ApiException\Contracts\ApiException; +use Liateam\ApiExceptions\Contracts\ApiException; class CustomDefaultException extends ApiException { diff --git a/src/Exceptions/CustomModelNotFoundException.php b/src/Exceptions/CustomModelNotFoundException.php index 81487b2..6daa1da 100644 --- a/src/Exceptions/CustomModelNotFoundException.php +++ b/src/Exceptions/CustomModelNotFoundException.php @@ -4,7 +4,7 @@ use Throwable; use Illuminate\Http\Response; -use Liateam\ApiException\Contracts\ApiException; +use Liateam\ApiExceptions\Contracts\ApiException; class CustomModelNotFoundException extends ApiException { diff --git a/src/Exceptions/CustomNotFoundHttpException.php b/src/Exceptions/CustomNotFoundHttpException.php index bd0831d..56d25af 100644 --- a/src/Exceptions/CustomNotFoundHttpException.php +++ b/src/Exceptions/CustomNotFoundHttpException.php @@ -2,9 +2,9 @@ namespace Liateam\ApiExceptions\Exceptions; -use Illuminate\Http\Response; -use Liateam\ApiException\Contracts\ApiException; use Throwable; +use Illuminate\Http\Response; +use Liateam\ApiExceptions\Contracts\ApiException; class CustomNotFoundHttpException extends ApiException { diff --git a/src/Exceptions/CustomRouteNotFoundException.php b/src/Exceptions/CustomRouteNotFoundException.php index b47ff18..ff42599 100644 --- a/src/Exceptions/CustomRouteNotFoundException.php +++ b/src/Exceptions/CustomRouteNotFoundException.php @@ -4,7 +4,7 @@ use Throwable; use Illuminate\Http\Response; -use Liateam\ApiException\Contracts\ApiException; +use Liateam\ApiExceptions\Contracts\ApiException; class CustomRouteNotFoundException extends ApiException { diff --git a/src/Exceptions/CustomUnauthorizedException.php b/src/Exceptions/CustomUnauthorizedException.php index 1e92bbb..306d37c 100644 --- a/src/Exceptions/CustomUnauthorizedException.php +++ b/src/Exceptions/CustomUnauthorizedException.php @@ -4,7 +4,7 @@ use Throwable; use Illuminate\Http\Response; -use Liateam\ApiException\Contracts\ApiException; +use Liateam\ApiExceptions\Contracts\ApiException; class CustomUnauthorizedException extends ApiException { diff --git a/src/Exceptions/CustomUnexpectedException.php b/src/Exceptions/CustomUnexpectedException.php index 6fc3bc4..7888aa6 100644 --- a/src/Exceptions/CustomUnexpectedException.php +++ b/src/Exceptions/CustomUnexpectedException.php @@ -4,7 +4,7 @@ use Throwable; use Illuminate\Http\Response; -use Liateam\ApiException\Contracts\ApiException; +use Liateam\ApiExceptions\Contracts\ApiException; class CustomUnexpectedException extends ApiException { diff --git a/src/Exceptions/CustomValidationException.php b/src/Exceptions/CustomValidationException.php index aa46d92..6bdf743 100644 --- a/src/Exceptions/CustomValidationException.php +++ b/src/Exceptions/CustomValidationException.php @@ -4,7 +4,7 @@ use Throwable; use Illuminate\Http\Response; -use Liateam\ApiException\Contracts\ApiException; +use Liateam\ApiExceptions\Contracts\ApiException; class CustomValidationException extends ApiException { diff --git a/src/Handlers/ApiException.php b/src/Handlers/ApiException.php index 4801ece..9965d7d 100644 --- a/src/Handlers/ApiException.php +++ b/src/Handlers/ApiException.php @@ -2,10 +2,10 @@ namespace Liateam\ApiExceptions\Handlers; -use Illuminate\Http\Response; use Throwable; +use Illuminate\Http\Response; use Liateam\ApiResponse\Contracts\ResponseContract; -use Liateam\ApiException\Exceptions\CustomDefaultException; +use Liateam\ApiExceptions\Exceptions\CustomDefaultException; /** * The classic CoR (Chain of Responsibility) pattern declares a single role for objects that make up a diff --git a/src/config/exceptions.php b/src/config/exceptions.php index a04e477..8353079 100644 --- a/src/config/exceptions.php +++ b/src/config/exceptions.php @@ -3,13 +3,13 @@ use \Illuminate\Auth\AuthenticationException; use Illuminate\Validation\ValidationException; use \Illuminate\Database\Eloquent\ModelNotFoundException; -use \Liateam\ApiException\Exceptions\CustomDefaultException; -use \Liateam\ApiException\Exceptions\CustomValidationException; -use \Liateam\ApiException\Exceptions\CustomNotFoundHttpException; -use \Liateam\ApiException\Exceptions\CustomUnauthorizedException; -use \Liateam\ApiException\Exceptions\CustomModelNotFoundException; +use \Liateam\ApiExceptions\Exceptions\CustomDefaultException; +use \Liateam\ApiExceptions\Exceptions\CustomValidationException; +use \Liateam\ApiExceptions\Exceptions\CustomNotFoundHttpException; +use \Liateam\ApiExceptions\Exceptions\CustomUnauthorizedException; +use \Liateam\ApiExceptions\Exceptions\CustomModelNotFoundException; use \Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use \Liateam\ApiException\Exceptions\CustomAuthenticationException; +use \Liateam\ApiExceptions\Exceptions\CustomAuthenticationException; use \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; return [