Improve dbus error handling

Fixes #787
This commit is contained in:
AsamK 2021-10-27 20:00:36 +02:00
parent ce7aa580b6
commit 1fae09433d
2 changed files with 14 additions and 10 deletions

View file

@ -388,63 +388,67 @@ public interface Signal extends DBusInterface {
class AttachmentInvalid extends DBusExecutionException { class AttachmentInvalid extends DBusExecutionException {
public AttachmentInvalid(final String message) { public AttachmentInvalid(final String message) {
super(message); super("Invalid attachment: " + message);
} }
} }
class InvalidUri extends DBusExecutionException { class InvalidUri extends DBusExecutionException {
public InvalidUri(final String message) { public InvalidUri(final String message) {
super(message); super("Invalid uri: " + message);
} }
} }
class Failure extends DBusExecutionException { class Failure extends DBusExecutionException {
public Failure(final Exception e) {
super("Failure: " + e.getMessage() + " (" + e.getClass().getSimpleName() + ")");
}
public Failure(final String message) { public Failure(final String message) {
super(message); super("Failure: " + message);
} }
} }
class DeviceNotFound extends DBusExecutionException { class DeviceNotFound extends DBusExecutionException {
public DeviceNotFound(final String message) { public DeviceNotFound(final String message) {
super(message); super("Device not found: " + message);
} }
} }
class GroupNotFound extends DBusExecutionException { class GroupNotFound extends DBusExecutionException {
public GroupNotFound(final String message) { public GroupNotFound(final String message) {
super(message); super("Group not found: " + message);
} }
} }
class InvalidGroupId extends DBusExecutionException { class InvalidGroupId extends DBusExecutionException {
public InvalidGroupId(final String message) { public InvalidGroupId(final String message) {
super(message); super("Invalid group id: " + message);
} }
} }
class LastGroupAdmin extends DBusExecutionException { class LastGroupAdmin extends DBusExecutionException {
public LastGroupAdmin(final String message) { public LastGroupAdmin(final String message) {
super(message); super("Last group admin: " + message);
} }
} }
class InvalidNumber extends DBusExecutionException { class InvalidNumber extends DBusExecutionException {
public InvalidNumber(final String message) { public InvalidNumber(final String message) {
super(message); super("Invalid number: " + message);
} }
} }
class UntrustedIdentity extends DBusExecutionException { class UntrustedIdentity extends DBusExecutionException {
public UntrustedIdentity(final String message) { public UntrustedIdentity(final String message) {
super(message); super("Untrusted identity: " + message);
} }
} }
} }

View file

@ -158,7 +158,7 @@ public class DbusSignalImpl implements Signal {
} catch (AttachmentInvalidException e) { } catch (AttachmentInvalidException e) {
throw new Error.AttachmentInvalid(e.getMessage()); throw new Error.AttachmentInvalid(e.getMessage());
} catch (IOException e) { } catch (IOException e) {
throw new Error.Failure(e.getMessage()); throw new Error.Failure(e);
} catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) { } catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
throw new Error.GroupNotFound(e.getMessage()); throw new Error.GroupNotFound(e.getMessage());
} }