mirror of https://github.com/nextcloud/server
fix(notifications): Add a dedicated exception when a notification was not parsed completely
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
c8e4a29dfa
commit
0d0c2cdaa0
|
@ -568,6 +568,7 @@ return array(
|
|||
'OCP\\Notification\\INotification' => $baseDir . '/lib/public/Notification/INotification.php',
|
||||
'OCP\\Notification\\INotifier' => $baseDir . '/lib/public/Notification/INotifier.php',
|
||||
'OCP\\Notification\\IncompleteNotificationException' => $baseDir . '/lib/public/Notification/IncompleteNotificationException.php',
|
||||
'OCP\\Notification\\IncompleteParsedNotificationException' => $baseDir . '/lib/public/Notification/IncompleteParsedNotificationException.php',
|
||||
'OCP\\Notification\\InvalidValueException' => $baseDir . '/lib/public/Notification/InvalidValueException.php',
|
||||
'OCP\\Notification\\UnknownNotificationException' => $baseDir . '/lib/public/Notification/UnknownNotificationException.php',
|
||||
'OCP\\OCM\\Events\\ResourceTypeRegisterEvent' => $baseDir . '/lib/public/OCM/Events/ResourceTypeRegisterEvent.php',
|
||||
|
|
|
@ -601,6 +601,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
|||
'OCP\\Notification\\INotification' => __DIR__ . '/../../..' . '/lib/public/Notification/INotification.php',
|
||||
'OCP\\Notification\\INotifier' => __DIR__ . '/../../..' . '/lib/public/Notification/INotifier.php',
|
||||
'OCP\\Notification\\IncompleteNotificationException' => __DIR__ . '/../../..' . '/lib/public/Notification/IncompleteNotificationException.php',
|
||||
'OCP\\Notification\\IncompleteParsedNotificationException' => __DIR__ . '/../../..' . '/lib/public/Notification/IncompleteParsedNotificationException.php',
|
||||
'OCP\\Notification\\InvalidValueException' => __DIR__ . '/../../..' . '/lib/public/Notification/InvalidValueException.php',
|
||||
'OCP\\Notification\\UnknownNotificationException' => __DIR__ . '/../../..' . '/lib/public/Notification/UnknownNotificationException.php',
|
||||
'OCP\\OCM\\Events\\ResourceTypeRegisterEvent' => __DIR__ . '/../../..' . '/lib/public/OCM/Events/ResourceTypeRegisterEvent.php',
|
||||
|
|
|
@ -36,6 +36,7 @@ use OCP\Notification\IDeferrableApp;
|
|||
use OCP\Notification\IDismissableNotifier;
|
||||
use OCP\Notification\IManager;
|
||||
use OCP\Notification\IncompleteNotificationException;
|
||||
use OCP\Notification\IncompleteParsedNotificationException;
|
||||
use OCP\Notification\INotification;
|
||||
use OCP\Notification\INotifier;
|
||||
use OCP\Notification\UnknownNotificationException;
|
||||
|
@ -365,13 +366,14 @@ class Manager implements IManager {
|
|||
}
|
||||
|
||||
if (!$notification->isValidParsed()) {
|
||||
throw new \InvalidArgumentException('The given notification has not been handled');
|
||||
$this->logger->info('Notification was claimed to be parsed, but was not fully parsed by ' . get_class($notifier) . ' [app: ' . $notification->getApp() . ', subject: ' . $notification->getSubject() . ']');
|
||||
throw new IncompleteParsedNotificationException();
|
||||
}
|
||||
}
|
||||
|
||||
if (!$notification->isValidParsed()) {
|
||||
$this->logger->info('Notification was not parsed by any notifier [app: ' . $notification->getApp() . ', subject: ' . $notification->getSubject() . ']');
|
||||
throw new \InvalidArgumentException('The given notification has not been handled');
|
||||
throw new IncompleteParsedNotificationException();
|
||||
}
|
||||
|
||||
return $notification;
|
||||
|
|
|
@ -52,10 +52,13 @@ interface INotifier {
|
|||
* @return INotification
|
||||
* @throws UnknownNotificationException When the notification was not prepared by a notifier
|
||||
* @throws AlreadyProcessedException When the notification is not needed anymore and should be deleted
|
||||
* @throws IncompleteParsedNotificationException Only to be thrown by the {@see IManager}
|
||||
* @since 9.0.0
|
||||
* @since 30.0.0 Notifiers should throw {@see UnknownNotificationException} instead of \InvalidArgumentException
|
||||
* when they did not handle the notification. Throwing \InvalidArgumentException directly is deprecated and will
|
||||
* be logged as an error in Nextcloud 39.
|
||||
* @since 30.0.0 Throws {@see IncompleteParsedNotificationException} when not all required fields
|
||||
* are set at the end of the manager or after a INotifier that claimed to have parsed the notification.
|
||||
*/
|
||||
public function prepare(INotification $notification, string $languageCode): INotification;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2024 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCP\Notification;
|
||||
|
||||
/**
|
||||
* Thrown when {@see \OCP\Notification\IManager::prepare()} is called with a notification
|
||||
* that does not have all required fields set at the end of the manager or after a INotifier
|
||||
* that claimed to have parsed the notification.
|
||||
*
|
||||
* Required fields are:
|
||||
*
|
||||
* - app
|
||||
* - user
|
||||
* - dateTime
|
||||
* - objectType
|
||||
* - objectId
|
||||
* - parsedSubject
|
||||
*
|
||||
* @since 30.0.0
|
||||
*/
|
||||
class IncompleteParsedNotificationException extends \InvalidArgumentException {
|
||||
}
|
Loading…
Reference in New Issue