Changeset View
Changeset View
Standalone View
Standalone View
src/app/Exceptions/Handler.php
<?php | <?php | ||||
namespace App\Exceptions; | namespace App\Exceptions; | ||||
use Exception; | use Exception; | ||||
use Illuminate\Auth\AuthenticationException; | use Illuminate\Auth\AuthenticationException; | ||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; | use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; | ||||
use Illuminate\Support\Facades\DB; | |||||
class Handler extends ExceptionHandler | class Handler extends ExceptionHandler | ||||
{ | { | ||||
/** | /** | ||||
* A list of the exception types that are not reported. | * A list of the exception types that are not reported. | ||||
* | * | ||||
* @var array | * @var array | ||||
*/ | */ | ||||
Show All 28 Lines | class Handler extends ExceptionHandler | ||||
* | * | ||||
* @param \Illuminate\Http\Request $request | * @param \Illuminate\Http\Request $request | ||||
* @param \Exception $exception | * @param \Exception $exception | ||||
* | * | ||||
* @return \Illuminate\Http\Response | * @return \Illuminate\Http\Response | ||||
*/ | */ | ||||
public function render($request, Exception $exception) | public function render($request, Exception $exception) | ||||
{ | { | ||||
// Rollback uncommitted transactions | |||||
while (DB::transactionLevel() > 0) { | |||||
DB::rollBack(); | |||||
} | |||||
return parent::render($request, $exception); | return parent::render($request, $exception); | ||||
} | } | ||||
protected function unauthenticated($request, AuthenticationException $exception) | protected function unauthenticated($request, AuthenticationException $exception) | ||||
{ | { | ||||
return $request->expectsJson() | return $request->expectsJson() | ||||
? response()->json(['message' => $exception->getMessage()], 401) | ? response()->json(['message' => $exception->getMessage()], 401) | ||||
: abort(401); | : abort(401); | ||||
} | } | ||||
} | } |