Skip to content

Commit f1b6e91

Browse files
committed
improvements: create flash message via thrown exception
1 parent 3d843aa commit f1b6e91

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Exception;
6+
7+
class ErrorToastException extends Exception
8+
{
9+
//
10+
}

bootstrap/app.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use App\Exceptions\ErrorToastException;
34
use App\Http\Middleware\EncryptCookies;
45
use App\Http\Middleware\HandleInertiaRequests;
56
use Illuminate\Cookie\Middleware\EncryptCookies as BaseEncryptCookies;
@@ -66,14 +67,20 @@
6667
return $response;
6768
}
6869
// Return JSON response for PrimeVue toast to display
70+
$errorSummary = "$statusCode - $errorTitles[$statusCode]";
71+
$errorDetail = $errorDetails[$statusCode];
72+
if (get_class($exception) === ErrorToastException::class) {
73+
$errorSummary = "$statusCode - Error";
74+
$errorDetail = $exception->getMessage();
75+
}
6976
return response()->json([
70-
'error_summary' => "$statusCode - $errorTitles[$statusCode]",
71-
'error_detail' => $errorDetails[$statusCode],
77+
'error_summary' => $errorSummary,
78+
'error_detail' => $errorDetail,
7279
], $statusCode);
7380
}
7481
} elseif ($statusCode === 419) {
7582
return back()->with([
76-
'flash_message' => 'The page expired, please try again.',
83+
'flash_warn' => 'The page expired, please try again.',
7784
]);
7885
}
7986

resources/js/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ createInertiaApp({
4444
summary: responseBody.error_summary,
4545
detail: responseBody.error_detail,
4646
life: 5000,
47-
styleClass: 'mb-0 mt-4',
47+
styleClass: 'shadow-lg mb-0 mt-4',
4848
});
4949
}
5050
});

0 commit comments

Comments
 (0)