Files
nl-jqrl-api/app/Exceptions/Handler.php

80 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
{
/**
* A list of the exception types that should not be reported.
*
* @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
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-06 11:49:51 -05:00
* Convert a validation exception into a response.
*
* @param \Illuminate\Http\Request $request
2017-07-15 19:48:06 +02:00
* @param \Illuminate\Validation\ValidationException $exception
2017-07-06 11:49:51 -05:00
* @return \Illuminate\Http\Response
*/
protected function invalid($request, ValidationException $exception)
{
2017-07-06 12:28:57 -05:00
$message = $exception->getMessage();
2017-07-06 11:49:51 -05:00
$errors = $exception->validator->errors()->messages();
return $request->expectsJson()
2017-07-06 12:28:57 -05:00
? response()->json(['message' => $message, 'errors' => $errors], 422)
2017-07-06 11:49:51 -05:00
: redirect()->back()->withInput()->withErrors(
2017-07-15 19:48:06 +02:00
$errors, $exception->errorBag
);
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
}