-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'hotfix/2.0.6' into 'develop'
tests completed See merge request php/packages/api-exceptions!13
- Loading branch information
Showing
25 changed files
with
797 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Liateam\ApiExceptions\Contracts; | ||
|
||
use Exception; | ||
use \Throwable; | ||
use Liateam\ApiResponse\Responses\FailureResponse; | ||
use Liateam\ApiResponse\Contracts\ResponseContract; | ||
|
||
abstract class ApiExceptionAbstract extends Exception | ||
{ | ||
/** | ||
* @var Throwable | ||
*/ | ||
protected $exception; | ||
|
||
|
||
protected $errors = []; | ||
/** | ||
* @var FailureResponse | ||
*/ | ||
private $failureResponse; | ||
|
||
/** | ||
* ApiException constructor. | ||
* @param Throwable $exception | ||
*/ | ||
public function __construct(Throwable $exception) | ||
{ | ||
$this->exception = $exception; | ||
parent::__construct($exception->getMessage(), $exception->getCode()); | ||
} | ||
|
||
/** | ||
* renders the error for api | ||
* | ||
* @return ResponseContract | ||
*/ | ||
public function render() | ||
{ | ||
$this->setCode($this->exception->getCode()); | ||
$this->setMessage($this->exception->getMessage()); | ||
$response = new FailureResponse($this->getCode(), $this->getMessage()); | ||
return $response | ||
->setResponseKey('error') | ||
->setResponseValue($this->getErrors()) | ||
->render(); | ||
} | ||
|
||
public function setErrors($errors) | ||
{ | ||
if (env('APP_DEBUG')) { | ||
$this->errors= [ | ||
'trace' => $this->exception->getTrace(), | ||
'line' => $this->exception->getLine(), | ||
]; | ||
} | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getErrors() | ||
{ | ||
return $this->errors; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.