@@ -133,7 +133,7 @@ protected void setOptionsResponseHeaders(@NotNull HttpServletResponse resp) {
133
133
resp .setStatus (204 );
134
134
}
135
135
136
- private void setAuthorizationProblem (@ NotNull HttpServletResponse resp , @ NotNull Exception e ) {
136
+ private void setAuthorizationProblem (@ NotNull HttpServletResponse resp , @ NotNull Exception e ) throws AqualityException {
137
137
resp .setStatus (401 );
138
138
resp .addHeader ("ErrorMessage" , !Objects .equals (e .getMessage (), "" ) ? e .getMessage () : "Are you sure you logged in?" );
139
139
setResponseBody (resp , !Objects .equals (e .getMessage (), "" ) ? e .getMessage () : "Are you sure you logged in?" );
@@ -193,47 +193,51 @@ protected void processResponse(HttpServletResponse response, String filePath) {
193
193
}
194
194
}
195
195
196
- protected void setResponseBody (HttpServletResponse resp , Object object ) {
196
+ protected void setResponseBody (HttpServletResponse resp , Object object ) throws AqualityException {
197
197
try {
198
198
setJSONContentType (resp );
199
199
resp .getWriter ().write (mapper .serialize (object ));
200
200
} catch (IOException e ) {
201
- System . out . println ( "Cannot set response body! " );
201
+ throw new AqualityException ( "System was not able to write a response! Raise an Issue. " );
202
202
}
203
203
}
204
204
205
205
protected void handleException (HttpServletResponse resp , @ NotNull Exception e ) {
206
206
e .printStackTrace ();
207
- switch (e .getClass ().getSimpleName ()) {
208
- case "UnsupportedOperationException" :
209
- setNotImplementedFunction (resp , e );
210
- return ;
211
- case "AuthenticationException" :
212
- setAuthorizationProblem (resp , e );
213
- return ;
214
- case "AqualityParametersException" :
215
- case "AqualityPermissionsException" :
216
- case "AqualityException" :
217
- case "InvalidFormatException" :
218
- case "AqualityQueryParameterException" :
219
- case "AqualitySQLException" :
220
- AqualityException exception = (AqualityException ) e ;
221
- resp .setStatus (exception .getResponseCode ());
222
- resp .addHeader ("ErrorMessage" , exception .getMessage ());
223
- setResponseBody (resp , new ErrorDto (exception .getMessage ()));
224
- return ;
225
- default :
226
- setUnknownIssue (resp );
207
+ try {
208
+ switch (e .getClass ().getSimpleName ()) {
209
+ case "UnsupportedOperationException" :
210
+ setNotImplementedFunction (resp , e );
211
+ return ;
212
+ case "AuthenticationException" :
213
+ setAuthorizationProblem (resp , e );
214
+ return ;
215
+ case "AqualityParametersException" :
216
+ case "AqualityPermissionsException" :
217
+ case "AqualityException" :
218
+ case "InvalidFormatException" :
219
+ case "AqualityQueryParameterException" :
220
+ case "AqualitySQLException" :
221
+ AqualityException exception = (AqualityException ) e ;
222
+ resp .setStatus (exception .getResponseCode ());
223
+ resp .addHeader ("ErrorMessage" , exception .getMessage ());
224
+ setResponseBody (resp , new ErrorDto (exception .getMessage ()));
225
+ return ;
226
+ default :
227
+ setUnknownIssue (resp );
228
+ }
229
+ } catch (AqualityException ex ) {
230
+ handleException (resp , ex );
227
231
}
228
232
}
229
233
230
- private void setNotImplementedFunction (@ NotNull HttpServletResponse resp , @ NotNull Exception e ) {
234
+ private void setNotImplementedFunction (@ NotNull HttpServletResponse resp , @ NotNull Exception e ) throws AqualityException {
231
235
resp .setStatus (501 );
232
236
resp .addHeader ("ErrorMessage" , e .getMessage ());
233
237
setResponseBody (resp , new ErrorDto (e .getMessage ()));
234
238
}
235
239
236
- private void setUnknownIssue (@ NotNull HttpServletResponse resp ) {
240
+ private void setUnknownIssue (@ NotNull HttpServletResponse resp ) throws AqualityException {
237
241
resp .setStatus (500 );
238
242
resp .addHeader ("ErrorMessage" , "Unknown Issue." );
239
243
setResponseBody (resp , new ErrorDto ("Unknown Issue." ));
0 commit comments