Files
spa-api/app/Exceptions/Handler.php

85 lines
2.2 KiB
PHP
Raw Normal View History

<?php
namespace App\Exceptions;
2014-11-18 22:48:38 -06:00
use Exception;
2016-07-10 16:35:03 -05:00
use Illuminate\Auth\AuthenticationException;
2017-07-06 11:49:51 -05:00
use Illuminate\Validation\ValidationException;
2014-11-18 22:48:38 -06:00
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
2015-02-22 20:47:03 -06:00
class Handler extends ExceptionHandler
{
/**
2017-07-19 16:21:03 -05:00
* A list of the exception types that are not reported.
2015-02-22 20:47:03 -06:00
*
* @var array
*/
protected $dontReport = [
2017-05-06 16:11:24 -04:00
//
2015-02-22 20:47:03 -06:00
];
2014-12-02 17:21:16 -06:00
2017-07-19 16:21:03 -05:00
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];
2015-02-22 20:47:03 -06:00
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
2015-02-22 20:47:03 -06:00
* @return void
*/
public function report(Exception $exception)
2015-02-22 20:47:03 -06:00
{
parent::report($exception);
2015-02-22 20:47:03 -06:00
}
2014-11-18 22:48:38 -06:00
2015-02-22 20:47:03 -06:00
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
2015-02-22 20:47:03 -06:00
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
2015-02-22 20:47:03 -06:00
{
return parent::render($request, $exception);
2015-02-22 20:47:03 -06:00
}
2016-05-26 10:00:14 -05:00
/**
2017-07-19 16:21:03 -05:00
* Convert a validation exception into a JSON response.
2017-07-06 11:49:51 -05:00
*
* @param \Illuminate\Http\Request $request
2017-07-15 19:48:06 +02:00
* @param \Illuminate\Validation\ValidationException $exception
2017-07-19 16:21:03 -05:00
* @return \Illuminate\Http\JsonResponse
2017-07-06 11:49:51 -05:00
*/
2017-07-19 16:21:03 -05:00
protected function invalidJson($request, ValidationException $exception)
2017-07-06 11:49:51 -05:00
{
2017-07-19 16:21:03 -05:00
return response()->json([
'message' => $exception->getMessage(),
'errors' => $exception->errors(),
2017-07-19 17:26:48 -05:00
], $exception->status);
2017-07-06 11:49:51 -05:00
}
/**
* Convert an authentication exception into a response.
2016-05-26 10:00:14 -05:00
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
2016-05-26 10:00:14 -05:00
* @return \Illuminate\Http\Response
*/
protected function unauthenticated($request, AuthenticationException $exception)
2016-05-26 10:00:14 -05:00
{
2017-05-06 16:11:24 -04:00
return $request->expectsJson()
2017-05-25 09:48:50 +02:00
? response()->json(['message' => 'Unauthenticated.'], 401)
2017-05-06 16:11:24 -04:00
: redirect()->guest(route('login'));
2016-05-26 10:00:14 -05:00
}
2014-11-18 22:48:38 -06:00
}