From f240da135e3f9bebb34ffc754ab65dcb2dac2214 Mon Sep 17 00:00:00 2001 From: Michal Feher Date: Fri, 8 Dec 2023 10:29:20 +0100 Subject: [PATCH] error mail notification for vacations --- .../Commands/SyncVacationsFromIntranet.php | 11 +++- be/app/Mail/Error.php | 64 +++++++++++++++++++ be/resources/views/error.blade.php | 1 + 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 be/app/Mail/Error.php create mode 100644 be/resources/views/error.blade.php diff --git a/be/app/Console/Commands/SyncVacationsFromIntranet.php b/be/app/Console/Commands/SyncVacationsFromIntranet.php index 224e80a..79aa0f5 100644 --- a/be/app/Console/Commands/SyncVacationsFromIntranet.php +++ b/be/app/Console/Commands/SyncVacationsFromIntranet.php @@ -2,8 +2,10 @@ namespace App\Console\Commands; +use App\Mail\Error; use App\Services\Intranet\IntranetService; use Illuminate\Console\Command; +use Illuminate\Support\Facades\Mail; class SyncVacationsFromIntranet extends Command { @@ -30,7 +32,14 @@ class SyncVacationsFromIntranet extends Command { $intranetService = new IntranetService(); - $intranetService->syncVacations(); + try { + $intranetService->syncVacations(); + } catch (\Exception $e) { + Mail::to('feher@studiotem.com')->send(new Error($e)); + + return Command::FAILURE; + } + return Command::SUCCESS; } } diff --git a/be/app/Mail/Error.php b/be/app/Mail/Error.php new file mode 100644 index 0000000..5b348b7 --- /dev/null +++ b/be/app/Mail/Error.php @@ -0,0 +1,64 @@ +message = $e->getMessage(); + } + + + /** + * Get the message envelope. + * + * @return \Illuminate\Mail\Mailables\Envelope + */ + public function envelope() + { + return new Envelope( + subject: 'Task Manager Error', + ); + } + + /** + * Get the message content definition. + * + * @return \Illuminate\Mail\Mailables\Content + */ + public function content() + { + return new Content( + view: 'emails.error', + ); + } + + /** + * Get the attachments for the message. + * + * @return array + */ + public function attachments() + { + return []; + } +} diff --git a/be/resources/views/error.blade.php b/be/resources/views/error.blade.php new file mode 100644 index 0000000..24c01b6 --- /dev/null +++ b/be/resources/views/error.blade.php @@ -0,0 +1 @@ +Message: {{ $message }}