From 828feb753a1c20311d49320b556cd247a3e3039c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tollk=C3=BChn?= Date: Thu, 8 Oct 2026 13:29:03 +0200 Subject: [PATCH] - catch InvalidArgumentException for confirm and create - more userfriendly error page for malformed links --- lib/Controller/CalendarController.php | 64 +++++++++++++++++++-------- 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/lib/Controller/CalendarController.php b/lib/Controller/CalendarController.php index a9b2e35..9f1b2ed 100644 --- a/lib/Controller/CalendarController.php +++ b/lib/Controller/CalendarController.php @@ -6,6 +6,7 @@ namespace OCA\AToCal\Controller; use OCA\AToCal\AppInfo\Application; use OCP\AppFramework\Controller; +use OCP\AppFramework\Http; use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\Attribute\NoCSRFRequired; use OCP\AppFramework\Http\RedirectResponse; @@ -89,15 +90,19 @@ class CalendarController extends Controller string $location = '', string $url = '' ): TemplateResponse { - $data = $this->validateEventData( - $summary, - $description, - $start, - $end, - $organizer, - $location, - $url - ); + try { + $data = $this->validateEventData( + $summary, + $description, + $start, + $end, + $organizer, + $location, + $url + ); + } catch (\InvalidArgumentException $e) { + return $this->renderError($e); + } $user = $this->userSession->getUser(); @@ -129,15 +134,19 @@ class CalendarController extends Controller string $url = '', string $calendarId = '' ): RedirectResponse|TemplateResponse { - $data = $this->validateEventData( - $summary, - $description, - $start, - $end, - $organizer, - $location, - $url - ); + try { + $data = $this->validateEventData( + $summary, + $description, + $start, + $end, + $organizer, + $location, + $url + ); + } catch (\InvalidArgumentException $e) { + return $this->renderError($e); + } $user = $this->userSession->getUser(); @@ -242,6 +251,25 @@ class CalendarController extends Controller return ''; } + /** + * Friendly error page (HTTP 400) for a malformed link, + * instead of an uncaught exception and a 500 error page. + */ + private function renderError(\InvalidArgumentException $e): TemplateResponse + { + return new TemplateResponse( + 'core', + 'error', + [ + 'errors' => [ + ['error' => $e->getMessage(), 'hint' => ''], + ], + ], + TemplateResponse::RENDER_AS_ERROR, + Http::STATUS_BAD_REQUEST + ); + } + /** * Render the confirmation page, optionally with an error message. */