A
A
Alexander Shvedov2020-02-05 22:06:08
Laravel
Alexander Shvedov, 2020-02-05 22:06:08

How to return throw correctly in laravel?

How to return throw correctly in laravel?
The problem is if you return

catch (\Exception $exception){
            return response('Сервер недоступен обратитесь к системному администратору' . $exception,500);
        }

Then axios recognizes it as .then how can I throw it as expt to make it work .catch tried to see how the validator does it but did not find it I will be grateful for any help

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Shvedov, 2020-02-05
@constintmid

Answer found, maybe it will help someone

return response()->exception('Сервер недоступен обратитесь к системному администратору' . $exception,500);

Y
Yaroslav Serbin, 2020-02-05
@ATLANT1S

return response()->json(['message' => 'Сервер недоступен обратитесь к системному администратору'], 500);

axios.get('/user/12345')
  .catch(function (error) {
    if (error.message) {
      console.log('Error', error.message);
    }
    console.log(error);
  });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question