Skip to content

Commit

Permalink
🎨 MessageException debug level #222
Browse files Browse the repository at this point in the history
  • Loading branch information
trydofor committed May 14, 2024
1 parent 0a05d45 commit 3e98ab8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion observe/docs
Submodule docs updated 0 files
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import pro.fessional.mirana.data.R;
import pro.fessional.mirana.pain.CodeException;
import pro.fessional.mirana.pain.HttpStatusException;
import pro.fessional.mirana.pain.MessageException;
import pro.fessional.mirana.text.JsonTemplate;
import pro.fessional.wings.slardar.context.LocaleZoneIdUtil;
import pro.fessional.wings.slardar.context.TerminalContextException;
Expand Down Expand Up @@ -55,8 +56,8 @@ public DefaultExceptionResolver(SimpleResponse defaultResponse, MessageSource me
@Override
protected SimpleResponse resolve(@NotNull Exception exception) {
SimpleResponse response = null;
Throwable cause = exception;
try {
Throwable cause = exception;
for (; response == null && cause != null; cause = cause.getCause()) {
if (cause instanceof HttpStatusException ex) {
response = handle(ex);
Expand All @@ -77,10 +78,14 @@ else if (cause instanceof AccessDeniedException ex) {
response = handleAccessDenied(ex);
}
}

if (response == null) {
cause = exception;
}
// handler
if (handler != null) {
// use original exception if response is null, otherwise the cause
response = handler.handle(response == null ? exception : cause, response);
response = handler.handle(cause, response);
}
}
catch (Throwable e) {
Expand All @@ -92,7 +97,12 @@ else if (cause instanceof AccessDeniedException ex) {
response = defaultResponse;
}
else {
log.debug("handled exception, response simple", exception);
if (cause instanceof MessageException) {
log.debug("handled MessageException, response simple", exception);
}
else {
log.info("handled exception, response simple", exception);
}
}

return response;
Expand Down Expand Up @@ -123,7 +133,7 @@ protected SimpleResponse handle(CodeException cex) {
return new SimpleResponse(defaultResponse.getHttpStatus(), defaultResponse.getContentType(), body);
}

protected SimpleResponse handleUnauthorized(Exception ex) {
protected SimpleResponse handleUnauthorized(Exception ignore) {
final String body = JsonTemplate.obj(obj -> {
obj.putVal("success", false);
String code = AuthnErrorEnum.Unauthorized.getCode();
Expand All @@ -133,7 +143,7 @@ protected SimpleResponse handleUnauthorized(Exception ex) {
return new SimpleResponse(HttpStatus.UNAUTHORIZED.value(), defaultResponse.getContentType(), body);
}

protected SimpleResponse handleAccessDenied(Exception ex) {
protected SimpleResponse handleAccessDenied(Exception ignore) {
final String body = JsonTemplate.obj(obj -> {
obj.putVal("success", false);
String code = AuthzErrorEnum.AccessDenied.getCode();
Expand Down

0 comments on commit 3e98ab8

Please sign in to comment.