[Warning] Penambahan Simulasi dan Aturan Jurnal SINTA
This commit is contained in:
@@ -4,9 +4,11 @@ use App\Http\Middleware\CheckPermission;
|
||||
use App\Http\Middleware\EnsureBawahanPresensi;
|
||||
use App\Http\Middleware\SetPermissionsTeamId;
|
||||
use App\Http\Middleware\UntanSSO;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Foundation\Configuration\Exceptions;
|
||||
use Illuminate\Foundation\Configuration\Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
return Application::configure(basePath: dirname(__DIR__))
|
||||
->withRouting(
|
||||
@@ -39,4 +41,29 @@ return Application::configure(basePath: dirname(__DIR__))
|
||||
$exceptions->shouldRenderJsonWhen(
|
||||
fn ($request, $e) => $request->is('api/*') || $request->expectsJson()
|
||||
);
|
||||
|
||||
// Koneksi ke database gagal (SQLSTATE 08006), biasanya karena diakses dari luar jaringan UNTAN.
|
||||
$exceptions->render(function (QueryException $e, Request $request) {
|
||||
if (! str_contains($e->getMessage(), 'SQLSTATE[08006]')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
preg_match('/connection to server at "([^"]+)"/', $e->getMessage(), $cocok);
|
||||
$host = $cocok[1] ?? config('database.connections.'.$e->getConnectionName().'.host', 'database');
|
||||
$pesan = "Tidak dapat menghubungkan server {$host} dengan jaringan public, silahkan gunakan jaringan UNTAN";
|
||||
|
||||
if ($request->is('api/*') || $request->expectsJson()) {
|
||||
return response()->json([
|
||||
'status' => 'warning',
|
||||
'message' => $pesan,
|
||||
], 503);
|
||||
}
|
||||
|
||||
// Hindari redirect berulang bila halaman sebelumnya juga membutuhkan database.
|
||||
if (url()->previous() === $request->fullUrl()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return back()->with('warning', $pesan);
|
||||
});
|
||||
})->create();
|
||||
|
||||
Reference in New Issue
Block a user