Refactor error handling internally to follow RFC7807 (#362)
* Refactor error handling internally to follow RFC7807 * style fixes
This commit is contained in:
@@ -2,25 +2,38 @@
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use App\Models\Pirep;
|
||||
|
||||
/**
|
||||
* Class PirepCancelled
|
||||
*/
|
||||
class PirepCancelled extends HttpException
|
||||
{
|
||||
public function __construct(
|
||||
string $message = null,
|
||||
\Exception $previous = null,
|
||||
int $code = 0,
|
||||
array $headers = []
|
||||
) {
|
||||
private $pirep;
|
||||
|
||||
public function __construct(Pirep $pirep)
|
||||
{
|
||||
$this->pirep = $pirep;
|
||||
parent::__construct(
|
||||
400,
|
||||
'PIREP has been cancelled, updates are not allowed',
|
||||
$previous,
|
||||
$headers,
|
||||
$code
|
||||
'PIREP has been cancelled, updates are not allowed'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the RFC 7807 error type (without the URL root)
|
||||
*/
|
||||
public function getErrorType(): string
|
||||
{
|
||||
return 'pirep-cancelled';
|
||||
}
|
||||
|
||||
public function getErrorDetails(): string
|
||||
{
|
||||
return $this->getMessage();
|
||||
}
|
||||
|
||||
public function getErrorMetadata(): array
|
||||
{
|
||||
return [
|
||||
'pirep_id' => $this->pirep->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user