2019-08-21 20:17:44 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Exceptions\Converters;
|
|
|
|
|
2019-11-19 23:06:07 +08:00
|
|
|
use App\Exceptions\AbstractHttpException;
|
2019-08-21 20:17:44 +08:00
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException as SymfonyHttpException;
|
|
|
|
|
2019-11-19 23:06:07 +08:00
|
|
|
class SymfonyException extends AbstractHttpException
|
2019-08-21 20:17:44 +08:00
|
|
|
{
|
|
|
|
private $exception;
|
|
|
|
|
|
|
|
public function __construct(SymfonyHttpException $exception)
|
|
|
|
{
|
|
|
|
$this->exception = $exception;
|
|
|
|
parent::__construct(
|
|
|
|
$exception->getStatusCode(),
|
2019-08-23 00:12:44 +08:00
|
|
|
$exception->getMessage(),
|
|
|
|
null,
|
|
|
|
$exception->getHeaders()
|
2019-08-21 20:17:44 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the RFC 7807 error type (without the URL root)
|
|
|
|
*/
|
|
|
|
public function getErrorType(): string
|
|
|
|
{
|
2019-08-23 00:12:44 +08:00
|
|
|
return 'http-exception';
|
2019-08-21 20:17:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the detailed error string
|
|
|
|
*/
|
|
|
|
public function getErrorDetails(): string
|
|
|
|
{
|
|
|
|
return $this->getMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an array with the error details, merged with the RFC7807 response
|
|
|
|
*/
|
|
|
|
public function getErrorMetadata(): array
|
|
|
|
{
|
|
|
|
// Only add trace if in dev
|
|
|
|
if (config('app.env') === 'dev') {
|
|
|
|
return [
|
|
|
|
'trace' => $this->exception->getTrace()[0],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|