- catch InvalidArgumentException for confirm and create

- more userfriendly error page for malformed links
This commit is contained in:
stefan.tollkuehn committed 2026-10-08 13:29:03 +02:00
1 parent 35d5185084
commit 828feb753a
1 file changed
+28
+28
View File
@@ -6,6 +6,7 @@ namespace OCA\AToCal\Controller;
use OCA\AToCal\AppInfo\Application; use OCA\AToCal\AppInfo\Application;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired; use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\RedirectResponse;
@@ -89,6 +90,7 @@ class CalendarController extends Controller
string $location = '', string $location = '',
string $url = '' string $url = ''
): TemplateResponse { ): TemplateResponse {
try {
$data = $this->validateEventData( $data = $this->validateEventData(
$summary, $summary,
$description, $description,
@@ -98,6 +100,9 @@ class CalendarController extends Controller
$location, $location,
$url $url
); );
} catch (\InvalidArgumentException $e) {
return $this->renderError($e);
}
$user = $this->userSession->getUser(); $user = $this->userSession->getUser();
@@ -129,6 +134,7 @@ class CalendarController extends Controller
string $url = '', string $url = '',
string $calendarId = '' string $calendarId = ''
): RedirectResponse|TemplateResponse { ): RedirectResponse|TemplateResponse {
try {
$data = $this->validateEventData( $data = $this->validateEventData(
$summary, $summary,
$description, $description,
@@ -138,6 +144,9 @@ class CalendarController extends Controller
$location, $location,
$url $url
); );
} catch (\InvalidArgumentException $e) {
return $this->renderError($e);
}
$user = $this->userSession->getUser(); $user = $this->userSession->getUser();
@@ -242,6 +251,25 @@ class CalendarController extends Controller
return ''; 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. * Render the confirmation page, optionally with an error message.
*/ */