- catch InvalidArgumentException for confirm and create
- more userfriendly error page for malformed links
This commit is contained in:
1 parent
35d5185084
commit
828feb753a
1 file changed
+46
-18
@@ -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,15 +90,19 @@ class CalendarController extends Controller
|
|||||||
string $location = '',
|
string $location = '',
|
||||||
string $url = ''
|
string $url = ''
|
||||||
): TemplateResponse {
|
): TemplateResponse {
|
||||||
$data = $this->validateEventData(
|
try {
|
||||||
$summary,
|
$data = $this->validateEventData(
|
||||||
$description,
|
$summary,
|
||||||
$start,
|
$description,
|
||||||
$end,
|
$start,
|
||||||
$organizer,
|
$end,
|
||||||
$location,
|
$organizer,
|
||||||
$url
|
$location,
|
||||||
);
|
$url
|
||||||
|
);
|
||||||
|
} catch (\InvalidArgumentException $e) {
|
||||||
|
return $this->renderError($e);
|
||||||
|
}
|
||||||
|
|
||||||
$user = $this->userSession->getUser();
|
$user = $this->userSession->getUser();
|
||||||
|
|
||||||
@@ -129,15 +134,19 @@ class CalendarController extends Controller
|
|||||||
string $url = '',
|
string $url = '',
|
||||||
string $calendarId = ''
|
string $calendarId = ''
|
||||||
): RedirectResponse|TemplateResponse {
|
): RedirectResponse|TemplateResponse {
|
||||||
$data = $this->validateEventData(
|
try {
|
||||||
$summary,
|
$data = $this->validateEventData(
|
||||||
$description,
|
$summary,
|
||||||
$start,
|
$description,
|
||||||
$end,
|
$start,
|
||||||
$organizer,
|
$end,
|
||||||
$location,
|
$organizer,
|
||||||
$url
|
$location,
|
||||||
);
|
$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.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in new issue
Block a user