fix: improve error handling in handleAction method with logging and user-friendly message

This commit is contained in:
Yoga Pangestu 2026-08-01 14:38:04 +07:00
parent 9cf3e2bb6b
commit 0126321a6e

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Log;
use Illuminate\Validation\ValidationException;
use Inertia\Inertia;
@ -21,7 +22,8 @@ protected function handleAction(callable $action, string $successMessage, string
return to_route($errorRoute ?? $redirectRoute, $parameters);
} catch (\Exception $e) {
Inertia::flash('toast', ['type' => 'error', 'message' => $e->getMessage()]);
Log::error($e->getMessage(), ['exception' => $e]);
Inertia::flash('toast', ['type' => 'error', 'message' => 'Terjadi kesalahan. Silakan coba lagi.']);
return to_route($errorRoute ?? $redirectRoute, $parameters);
}