notificationDaemon: Use registered D-Bus error

Instead of returning ad-hoc errors, register a custom error domain
and return appropriate GLib.Errors.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3159>
This commit is contained in:
Florian Müllner 2024-01-31 18:32:15 +01:00
parent 8f03eec3a3
commit f38e3f4b5d
2 changed files with 10 additions and 1 deletions

View File

@ -34,3 +34,10 @@ const modalDialogErrorNames = [
export const ModalDialogErrors = export const ModalDialogErrors =
registerErrorDomain('ModalDialog', modalDialogErrorNames); registerErrorDomain('ModalDialog', modalDialogErrorNames);
export const ModalDialogError = createErrorEnum(modalDialogErrorNames); export const ModalDialogError = createErrorEnum(modalDialogErrorNames);
const notificationErrorNames = [
'InvalidApp',
];
export const NotificationErrors =
registerErrorDomain('Notifications', notificationErrorNames, 'org.gtk');
export const NotificationError = createErrorEnum(notificationErrorNames);

View File

@ -12,6 +12,7 @@ import * as MessageTray from './messageTray.js';
import * as Params from '../misc/params.js'; import * as Params from '../misc/params.js';
import {loadInterfaceXML} from '../misc/fileUtils.js'; import {loadInterfaceXML} from '../misc/fileUtils.js';
import {NotificationErrors, NotificationError} from '../misc/dbusErrors.js';
const FdoNotificationsIface = loadInterfaceXML('org.freedesktop.Notifications'); const FdoNotificationsIface = loadInterfaceXML('org.freedesktop.Notifications');
@ -694,7 +695,8 @@ class GtkNotificationDaemon {
source = this._ensureAppSource(appId); source = this._ensureAppSource(appId);
} catch (e) { } catch (e) {
if (e instanceof InvalidAppError) { if (e instanceof InvalidAppError) {
invocation.return_dbus_error('org.gtk.Notifications.InvalidApp', invocation.return_error_literal(NotificationErrors,
NotificationError.INVALID_APP,
`The app by ID "${appId}" could not be found`); `The app by ID "${appId}" could not be found`);
return; return;
} }