2019-05-20 07:37:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Exceptions;
|
|
|
|
|
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
|
|
|
|
|
|
|
class Handler extends ExceptionHandler
|
|
|
|
{
|
2022-11-14 17:10:47 +01:00
|
|
|
/**
|
2023-08-01 16:33:55 +02:00
|
|
|
* The list of the inputs that are never flashed to the session on validation exceptions.
|
2019-05-20 07:37:41 +02:00
|
|
|
*
|
2022-11-17 16:46:29 +01:00
|
|
|
* @var array<int, string>
|
2019-05-20 07:37:41 +02:00
|
|
|
*/
|
|
|
|
protected $dontFlash = [
|
2021-12-02 13:15:53 +01:00
|
|
|
'current_password',
|
2019-05-20 07:37:41 +02:00
|
|
|
'password',
|
|
|
|
'password_confirmation',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
2021-12-02 13:15:53 +01:00
|
|
|
* Register the exception handling callbacks for the application.
|
2019-05-20 07:37:41 +02:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2021-12-02 13:15:53 +01:00
|
|
|
public function register()
|
2019-05-20 07:37:41 +02:00
|
|
|
{
|
2021-12-02 13:15:53 +01:00
|
|
|
$this->renderable(function (\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $exception, $request) {
|
2021-09-26 23:49:52 +02:00
|
|
|
return response()->json([
|
2022-11-22 15:15:52 +01:00
|
|
|
'message' => 'not found',
|
|
|
|
], 404);
|
2021-12-02 13:15:53 +01:00
|
|
|
});
|
|
|
|
|
2023-02-17 17:12:53 +01:00
|
|
|
$this->renderable(function (\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException $exception, $request) {
|
|
|
|
return response()->json([
|
|
|
|
'message' => 'unauthorized',
|
|
|
|
], 403);
|
|
|
|
});
|
|
|
|
|
2021-12-02 13:15:53 +01:00
|
|
|
$this->renderable(function (InvalidOtpParameterException $exception, $request) {
|
2021-09-17 23:45:08 +02:00
|
|
|
return response()->json([
|
|
|
|
'message' => 'invalid OTP parameters',
|
2022-11-22 15:15:52 +01:00
|
|
|
'reason' => [$exception->getMessage()],
|
2021-09-17 23:45:08 +02:00
|
|
|
], 400);
|
2021-12-02 13:15:53 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->renderable(function (InvalidQrCodeException $exception, $request) {
|
2021-09-07 23:01:53 +02:00
|
|
|
return response()->json([
|
2024-03-22 18:04:44 +01:00
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
], 400);
|
2021-12-02 13:15:53 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->renderable(function (InvalidSecretException $exception, $request) {
|
2021-09-17 23:45:08 +02:00
|
|
|
return response()->json([
|
2022-11-22 15:15:52 +01:00
|
|
|
'message' => 'not a valid base32 encoded secret', ], 400);
|
2021-12-02 13:15:53 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->renderable(function (DbEncryptionException $exception, $request) {
|
2021-11-26 11:21:57 +01:00
|
|
|
return response()->json([
|
2022-11-22 15:15:52 +01:00
|
|
|
'message' => $exception->getMessage(), ], 400);
|
2021-12-02 13:15:53 +01:00
|
|
|
});
|
2022-05-19 15:47:34 +02:00
|
|
|
|
2022-10-07 18:58:48 +02:00
|
|
|
$this->renderable(function (InvalidMigrationDataException $exception, $request) {
|
2022-06-20 17:47:23 +02:00
|
|
|
return response()->json([
|
2022-11-22 15:15:52 +01:00
|
|
|
'message' => __('errors.invalid_x_migration', ['appname' => $exception->getMessage()]),
|
|
|
|
], 400);
|
2022-10-07 18:58:48 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->renderable(function (UnsupportedMigrationException $exception, $request) {
|
|
|
|
return response()->json([
|
2022-11-22 15:15:52 +01:00
|
|
|
'message' => __('errors.unsupported_migration'),
|
|
|
|
], 400);
|
2022-10-07 18:58:48 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->renderable(function (EncryptedMigrationException $exception, $request) {
|
|
|
|
return response()->json([
|
2022-11-22 15:15:52 +01:00
|
|
|
'message' => __('errors.encrypted_migration'),
|
|
|
|
], 400);
|
2022-06-20 17:47:23 +02:00
|
|
|
});
|
|
|
|
|
2022-07-05 10:10:24 +02:00
|
|
|
$this->renderable(function (UndecipherableException $exception, $request) {
|
|
|
|
return response()->json([
|
2022-11-22 15:15:52 +01:00
|
|
|
'message' => __('errors.cannot_decipher_secret'),
|
|
|
|
], 400);
|
2022-07-05 10:10:24 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->renderable(function (UnsupportedOtpTypeException $exception, $request) {
|
|
|
|
return response()->json([
|
2022-11-22 15:15:52 +01:00
|
|
|
'message' => __('errors.unsupported_otp_type'),
|
|
|
|
], 400);
|
2022-07-05 10:10:24 +02:00
|
|
|
});
|
|
|
|
|
2022-05-19 15:47:34 +02:00
|
|
|
$this->renderable(function (\Illuminate\Auth\AuthenticationException $exception, $request) {
|
|
|
|
if ($exception->guards() === ['reverse-proxy-guard']) {
|
|
|
|
return response()->json([
|
2022-11-22 15:15:52 +01:00
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
], 407);
|
|
|
|
} else {
|
2022-05-19 15:47:34 +02:00
|
|
|
return response()->json([
|
2022-11-22 15:15:52 +01:00
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
], 401);
|
2022-05-19 15:47:34 +02:00
|
|
|
}
|
|
|
|
});
|
2019-05-26 16:44:46 +02:00
|
|
|
}
|
2022-11-22 15:15:52 +01:00
|
|
|
}
|