added more specific exceptions

This commit is contained in:
Sheldan
2020-05-13 23:46:58 +02:00
parent cf04687f04
commit b591ae497d
12 changed files with 134 additions and 20 deletions

View File

@@ -15,6 +15,7 @@ import dev.sheldan.abstracto.core.service.management.UserInServerService;
import dev.sheldan.abstracto.core.utils.CompletableFutureList;
import dev.sheldan.abstracto.modmail.config.ModMailFeature;
import dev.sheldan.abstracto.modmail.config.ModMailLoggingFeature;
import dev.sheldan.abstracto.modmail.exception.ModMailThreadNotFoundException;
import dev.sheldan.abstracto.modmail.models.database.*;
import dev.sheldan.abstracto.modmail.models.dto.ServerChoice;
import dev.sheldan.abstracto.modmail.models.template.*;
@@ -309,7 +310,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
messageService.addReactionToMessage("readReaction", modMailThread.getServer().getId(), message);
});
} else {
throw new AbstractoRunTimeException(String.format("Could not find mod mail thread with id %s", modMailThreadId));
throw new ModMailThreadNotFoundException(modMailThreadId);
}
}
@@ -348,7 +349,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
log.error("Failed to notify about mod mail exception.", e);
}
} else {
throw new AbstractoRunTimeException(String.format("Could not find mod mail thread with id %s", modMailTreadId));
throw new ModMailThreadNotFoundException(modMailTreadId);
}
}
@@ -406,7 +407,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
sendModMailFailure("modmail_exception_generic", innerModMailThread.getUser(), modMailThreadId, feedBack, e);
}
} else {
throw new AbstractoRunTimeException(String.format("Could not find mod mail thread with id %s", modMailThreadId));
throw new ModMailThreadNotFoundException(modMailThreadId);
}
});
} else {
@@ -446,7 +447,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
undoActionService.performActions(undoActions);
});
} else {
throw new AbstractoRunTimeException(String.format("Could not find mod mail thread with id %s", modMailThreadId));
throw new ModMailThreadNotFoundException(modMailThreadId);
}
}
@@ -476,7 +477,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
undoActionService.performActions(undoActions);
}
} else {
throw new AbstractoRunTimeException(String.format("Could not find mod mail thread with id %s", modMailThreadId));
throw new ModMailThreadNotFoundException(modMailThreadId);
}
}
@@ -532,7 +533,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
.futures(completableFutures)
.build();
} else {
throw new AbstractoRunTimeException(String.format("Could not find mod mail thread with id %s", modMailThreadId));
throw new ModMailThreadNotFoundException(modMailThreadId);
}
}
@@ -544,7 +545,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
log.info("Setting thread {} to closed in db.", modMailThread.getId());
modMailThreadManagementService.setModMailThreadState(modMailThread, ModMailThreadState.CLOSED);
} else {
throw new AbstractoRunTimeException(String.format("Could not find mod mail thread with id %s", modMailThreadId));
throw new ModMailThreadNotFoundException(modMailThreadId);
}
}
@@ -594,7 +595,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
return null;
});
} else {
throw new AbstractoRunTimeException(String.format("Could not find mod mail thread with id %s", modMailThreadId));
throw new ModMailThreadNotFoundException(modMailThreadId);
}
}
@@ -618,7 +619,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
self.saveMessageIds(messages, modMailThread, moderator, anonymous, true);
modMailThreadManagementService.setModMailThreadState(modMailThread, ModMailThreadState.MOD_REPLIED);
} else {
throw new AbstractoRunTimeException(String.format("Could not find mod mail thread with id %s", modMailThreadId));
throw new ModMailThreadNotFoundException(modMailThreadId);
}
}

View File

@@ -0,0 +1,28 @@
package dev.sheldan.abstracto.modmail.exception;
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.templating.Templatable;
import java.util.HashMap;
public class ModMailThreadNotFoundException extends AbstractoRunTimeException implements Templatable {
private Long modMailThreadId;
public ModMailThreadNotFoundException(Long modMailThreadId) {
super("");
this.modMailThreadId = modMailThreadId;
}
@Override
public String getTemplateName() {
return "modmail_cannot_find_modmail_thread_exception_text";
}
@Override
public Object getTemplateModel() {
HashMap<String, Long> params = new HashMap<>();
params.put("id", this.modMailThreadId);
return params;
}
}