Answer the question
In order to leave comments, you need to log in
How do you organize error output in laravel?
Hello. Recently I started to master laravel and I was faced with the question of how best to organize error output.
At the moment, I tried to organize it as follows:
1. I slightly expanded the basic Exception Handler and in the render method I see what type of request led to the error:
public function render($request, Exception $e)
{
$statusCode = $this->getStatusCode($e);
if ($request->wantsJson()) {
return response()->json(['message' => $e->getMessage()], $statusCode);
}
if (!config('app.debug')) {
return parent::render($request, $e);
}
return response()->view('errors', ['error' => $e->getMessage()], 500);
}
)
.error(function(data) {
$.notify(data.message, "error");
});
@section('flash')
@if(Session::has('flash_success'))
<div class="alertFlash alert alert-success">{!! session('flash_success') !!}</div>
@endif
@if(Session::has('flash_warning'))
<div class="alertFlash alert alert-warning">{!! session('flash_warning') !!}</div>
@endif
@if(Session::has('flash_error'))
<div class="alertFlash alert alert-danger">{!! session('flash_error') !!}</div>
@endif
@show
abort(500, 'Текст ошибки);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question