Skip to content

Commit

Permalink
Merge branch 'master' into 'develop'
Browse files Browse the repository at this point in the history
Master

See merge request php/packages/api-exceptions!11
  • Loading branch information
Pooria Arab committed Jan 10, 2021
2 parents 9824cbe + 98435c0 commit 3b9dfc3
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 21 deletions.
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand All @@ -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();
}
```

Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/ApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/CustomAuthenticationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Throwable;
use Illuminate\Http\Response;
use Liateam\ApiException\Contracts\ApiException;
use Liateam\ApiExceptions\Contracts\ApiException;

class CustomAuthenticationException extends ApiException
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/CustomDefaultException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/CustomModelNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Throwable;
use Illuminate\Http\Response;
use Liateam\ApiException\Contracts\ApiException;
use Liateam\ApiExceptions\Contracts\ApiException;

class CustomModelNotFoundException extends ApiException
{
Expand Down
4 changes: 2 additions & 2 deletions src/Exceptions/CustomNotFoundHttpException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/CustomRouteNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Throwable;
use Illuminate\Http\Response;
use Liateam\ApiException\Contracts\ApiException;
use Liateam\ApiExceptions\Contracts\ApiException;

class CustomRouteNotFoundException extends ApiException
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/CustomUnauthorizedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Throwable;
use Illuminate\Http\Response;
use Liateam\ApiException\Contracts\ApiException;
use Liateam\ApiExceptions\Contracts\ApiException;

class CustomUnauthorizedException extends ApiException
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/CustomUnexpectedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Throwable;
use Illuminate\Http\Response;
use Liateam\ApiException\Contracts\ApiException;
use Liateam\ApiExceptions\Contracts\ApiException;

class CustomUnexpectedException extends ApiException
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/CustomValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Throwable;
use Illuminate\Http\Response;
use Liateam\ApiException\Contracts\ApiException;
use Liateam\ApiExceptions\Contracts\ApiException;

class CustomValidationException extends ApiException
{
Expand Down
4 changes: 2 additions & 2 deletions src/Handlers/ApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/config/exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down

0 comments on commit 3b9dfc3

Please sign in to comment.