diff --git a/app/Http/Controllers/Private/Controller.php b/app/Http/Controllers/Private/Controller.php index 0d678f1..8ec4fd7 100644 --- a/app/Http/Controllers/Private/Controller.php +++ b/app/Http/Controllers/Private/Controller.php @@ -2,12 +2,23 @@ namespace App\Http\Controllers\Private; +use App\Contracts\ServiceResultError as ServiceResultErrorContract; use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Validation\ValidatesRequests; +use Illuminate\Http\Response; use Illuminate\Routing\Controller as BaseController; class Controller extends BaseController { use AuthorizesRequests, DispatchesJobs, ValidatesRequests; + + final protected function errors(ServiceResultErrorContract $result): never + { + if ($result->getCode() === Response::HTTP_UNPROCESSABLE_ENTITY) { + redirect()->back()->withInput()->withErrors($result->getErrors()); + exit; + } + abort($result->getCode(), $result->getMessage()); + } }