Don't allow cancels from certain states (#396)
* Don't allow cancels from certain states * Unused imports * Don't reset the state doubly * Move SetUserActive into listener; code cleanup * Unused imports * Add missing files into htaccess * Move Command contract to correct folder
This commit is contained in:
40
app/Exceptions/PirepCancelNotAllowed.php
Normal file
40
app/Exceptions/PirepCancelNotAllowed.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use App\Models\Pirep;
|
||||
|
||||
class PirepCancelNotAllowed extends HttpException
|
||||
{
|
||||
private $pirep;
|
||||
|
||||
public function __construct(Pirep $pirep)
|
||||
{
|
||||
$this->pirep = $pirep;
|
||||
parent::__construct(
|
||||
400,
|
||||
'This PIREP can\'t be cancelled'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the RFC 7807 error type (without the URL root)
|
||||
*/
|
||||
public function getErrorType(): string
|
||||
{
|
||||
return 'pirep-cancel-not-allowed';
|
||||
}
|
||||
|
||||
public function getErrorDetails(): string
|
||||
{
|
||||
return $this->getMessage();
|
||||
}
|
||||
|
||||
public function getErrorMetadata(): array
|
||||
{
|
||||
return [
|
||||
'pirep_id' => $this->pirep->id,
|
||||
'state' => $this->pirep->state,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user