Commit c71ec52
committed
refactor(application-form): better exception handling
There are currently many undesired conditions the code could run into
when it comes to the `RoleApplicationHandler` which we would not desire
and we would not be prepared for, particularly in situations where:
- We would somehow find ourselves handling application form
submissions in a non-guild environment.
- The arguments size including the clicked component ID as well as
the role name (the title of that component ID in essence) would
have an unexpected size.
- The staff-monitored application submissions text channel would not
be found by the bot.
We do not have entire control over these cases, but we need to handle
them properly and set ourselves up for success in the rare case they
happen.
Make `sendApplicationResult` throw an `IllegalArgumentException` with
descriptive messages if anything goes wrong, and log appropriate
stacktraces if anything goes wrong in the logger for easy debugging.
I thought about printing straight to the logger and not using any
`IllegalArgumentException` in the code (or at least, using a different
or maybe custom `Exception` but that would be too much), but with this
method, we get to see custom messages along with exceptions for each
individual case - all that without unnecessarily overcomplicating the
code and sacrificing its readability to a considerable extent.
Suggested-by: Zabuzard <zabuza.dev@gmail.com>
Signed-off-by: Chris Sdogkos <work@chris-sdogkos.com>1 parent 1507cc1 commit c71ec52
File tree
1 file changed
+28
-9
lines changed- application/src/main/java/org/togetherjava/tjbot/features/roleapplication
1 file changed
+28
-9
lines changedLines changed: 28 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
32 | | - | |
| 34 | + | |
33 | 35 | | |
| 36 | + | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
| |||
65 | 68 | | |
66 | 69 | | |
67 | 70 | | |
68 | | - | |
| 71 | + | |
69 | 72 | | |
70 | | - | |
71 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
72 | 83 | | |
73 | 84 | | |
74 | 85 | | |
75 | 86 | | |
76 | 87 | | |
77 | 88 | | |
78 | | - | |
| 89 | + | |
| 90 | + | |
79 | 91 | | |
80 | 92 | | |
81 | 93 | | |
| |||
125 | 137 | | |
126 | 138 | | |
127 | 139 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
132 | 151 | | |
133 | 152 | | |
134 | 153 | | |
| |||
0 commit comments