From aa352c254cfbba793c42023af1f04d9f9a9e0f88 Mon Sep 17 00:00:00 2001 From: gsd Date: Thu, 25 Apr 2024 19:22:20 +0300 Subject: [PATCH] err base handler --- .../java/app/annotations/exceptions/FailedAuthCheck.java | 4 +++- .../java/app/annotations/exceptions/InvalidCookie.java | 4 +++- .../java/app/annotations/exceptions/InvalidSecretKey.java | 4 +++- src/main/java/app/annotations/exceptions/LowPermition.java | 4 +++- src/main/java/app/annotations/exceptions/NeedCookie.java | 4 +++- .../java/app/annotations/exceptions/WaitRateLimit.java | 4 +++- src/main/java/app/exceptions/BaseWebException.java | 4 ++++ .../exceptions/RestResponseStatusExceptionResolver.java | 5 +++++ src/main/java/app/services/ProfileService.java | 7 ++++--- 9 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 src/main/java/app/exceptions/BaseWebException.java diff --git a/src/main/java/app/annotations/exceptions/FailedAuthCheck.java b/src/main/java/app/annotations/exceptions/FailedAuthCheck.java index e42e74e..c884846 100644 --- a/src/main/java/app/annotations/exceptions/FailedAuthCheck.java +++ b/src/main/java/app/annotations/exceptions/FailedAuthCheck.java @@ -1,4 +1,6 @@ package app.annotations.exceptions; -public class FailedAuthCheck extends RuntimeException{ +import app.exceptions.BaseWebException; + +public class FailedAuthCheck extends BaseWebException { } diff --git a/src/main/java/app/annotations/exceptions/InvalidCookie.java b/src/main/java/app/annotations/exceptions/InvalidCookie.java index 5f99bfc..2f03b91 100644 --- a/src/main/java/app/annotations/exceptions/InvalidCookie.java +++ b/src/main/java/app/annotations/exceptions/InvalidCookie.java @@ -1,4 +1,6 @@ package app.annotations.exceptions; -public class InvalidCookie extends RuntimeException{ +import app.exceptions.BaseWebException; + +public class InvalidCookie extends BaseWebException { } diff --git a/src/main/java/app/annotations/exceptions/InvalidSecretKey.java b/src/main/java/app/annotations/exceptions/InvalidSecretKey.java index 594b8f6..255f3e8 100644 --- a/src/main/java/app/annotations/exceptions/InvalidSecretKey.java +++ b/src/main/java/app/annotations/exceptions/InvalidSecretKey.java @@ -1,4 +1,6 @@ package app.annotations.exceptions; -public class InvalidSecretKey extends RuntimeException{ +import app.exceptions.BaseWebException; + +public class InvalidSecretKey extends BaseWebException { } diff --git a/src/main/java/app/annotations/exceptions/LowPermition.java b/src/main/java/app/annotations/exceptions/LowPermition.java index 6c872c9..5a76ef6 100644 --- a/src/main/java/app/annotations/exceptions/LowPermition.java +++ b/src/main/java/app/annotations/exceptions/LowPermition.java @@ -1,4 +1,6 @@ package app.annotations.exceptions; -public class LowPermition extends RuntimeException{ +import app.exceptions.BaseWebException; + +public class LowPermition extends BaseWebException { } diff --git a/src/main/java/app/annotations/exceptions/NeedCookie.java b/src/main/java/app/annotations/exceptions/NeedCookie.java index 88599d4..991a54e 100644 --- a/src/main/java/app/annotations/exceptions/NeedCookie.java +++ b/src/main/java/app/annotations/exceptions/NeedCookie.java @@ -1,4 +1,6 @@ package app.annotations.exceptions; -public class NeedCookie extends RuntimeException{ +import app.exceptions.BaseWebException; + +public class NeedCookie extends BaseWebException { } diff --git a/src/main/java/app/annotations/exceptions/WaitRateLimit.java b/src/main/java/app/annotations/exceptions/WaitRateLimit.java index d80207d..434ff3b 100644 --- a/src/main/java/app/annotations/exceptions/WaitRateLimit.java +++ b/src/main/java/app/annotations/exceptions/WaitRateLimit.java @@ -1,4 +1,6 @@ package app.annotations.exceptions; -public class WaitRateLimit extends RuntimeException { +import app.exceptions.BaseWebException; + +public class WaitRateLimit extends BaseWebException { } diff --git a/src/main/java/app/exceptions/BaseWebException.java b/src/main/java/app/exceptions/BaseWebException.java new file mode 100644 index 0000000..94f25fa --- /dev/null +++ b/src/main/java/app/exceptions/BaseWebException.java @@ -0,0 +1,4 @@ +package app.exceptions; + +public abstract class BaseWebException extends RuntimeException { +} diff --git a/src/main/java/app/exceptions/RestResponseStatusExceptionResolver.java b/src/main/java/app/exceptions/RestResponseStatusExceptionResolver.java index f235b8d..f71e6df 100644 --- a/src/main/java/app/exceptions/RestResponseStatusExceptionResolver.java +++ b/src/main/java/app/exceptions/RestResponseStatusExceptionResolver.java @@ -17,6 +17,11 @@ public class RestResponseStatusExceptionResolver extends DefaultHandlerException private final Logger logger = LoggerFactory.getLogger(getClass()); @Override protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { + //hand manualy created exception + if (ex instanceof BaseWebException) { + return super.doResolveException(request, response, handler, ex); + } + UUID uuid = UUID.randomUUID(); logger.error("[{}] Found error in request {} with path {}", uuid, request.getMethod(), request.getRequestURI()); logger.error("["+uuid+"]", ex); diff --git a/src/main/java/app/services/ProfileService.java b/src/main/java/app/services/ProfileService.java index 841bd21..8762ee0 100644 --- a/src/main/java/app/services/ProfileService.java +++ b/src/main/java/app/services/ProfileService.java @@ -5,6 +5,7 @@ import app.entities.Stats; import app.entities.db.Ban; import app.entities.db.Killfeed; import app.entities.other.SteamID; +import app.exceptions.BaseWebException; import app.services.db.*; import app.services.steam.SteamWebApi; import app.utils.SteamIDConverter; @@ -311,7 +312,7 @@ public class ProfileService { return profile; } - public class EmptyRequestPlayer extends RuntimeException {} - public class LowAdminPermition extends RuntimeException {} - public class NotFoundPlayer extends RuntimeException {} + public class EmptyRequestPlayer extends BaseWebException {} + public class LowAdminPermition extends BaseWebException {} + public class NotFoundPlayer extends BaseWebException {} }