From 71d2226862ee583d58317669d44fb4ddbfa03e7f Mon Sep 17 00:00:00 2001 From: Oleh Astappiev Date: Mon, 3 Jun 2024 15:30:11 +0200 Subject: [PATCH] fix: better exception handling --- .../interweb/server/config/ExceptionMappers.java | 14 ++++++++++++++ .../de/l3s/interweb/server/features/chat/Chat.java | 4 ++++ .../src/main/resources/application.properties | 1 + 3 files changed, 19 insertions(+) create mode 100644 interweb-server/src/main/java/de/l3s/interweb/server/config/ExceptionMappers.java diff --git a/interweb-server/src/main/java/de/l3s/interweb/server/config/ExceptionMappers.java b/interweb-server/src/main/java/de/l3s/interweb/server/config/ExceptionMappers.java new file mode 100644 index 00000000..8118779f --- /dev/null +++ b/interweb-server/src/main/java/de/l3s/interweb/server/config/ExceptionMappers.java @@ -0,0 +1,14 @@ +package de.l3s.interweb.server.config; + +import jakarta.validation.ValidationException; +import jakarta.ws.rs.core.Response; + +import org.jboss.resteasy.reactive.RestResponse; +import org.jboss.resteasy.reactive.server.ServerExceptionMapper; + +public class ExceptionMappers { + @ServerExceptionMapper + public RestResponse mapValidationException(ValidationException x) { + return RestResponse.status(Response.Status.BAD_REQUEST, x.getMessage()); + } +} diff --git a/interweb-server/src/main/java/de/l3s/interweb/server/features/chat/Chat.java b/interweb-server/src/main/java/de/l3s/interweb/server/features/chat/Chat.java index 0b96a1df..cbe77dc8 100644 --- a/interweb-server/src/main/java/de/l3s/interweb/server/features/chat/Chat.java +++ b/interweb-server/src/main/java/de/l3s/interweb/server/features/chat/Chat.java @@ -99,6 +99,10 @@ public static Uni> listByUser(Token token, String user, String order, query += " AND user = :user"; } + if (page <= 0) { + page = 1; // foolproof + } + return find(query, sort, params).page(page - 1, perPage).list(); } diff --git a/interweb-server/src/main/resources/application.properties b/interweb-server/src/main/resources/application.properties index f846c9a0..df14ac45 100644 --- a/interweb-server/src/main/resources/application.properties +++ b/interweb-server/src/main/resources/application.properties @@ -38,6 +38,7 @@ mp.jwt.verify.publickey.algorithm=HS256 quarkus.log.sentry=false quarkus.log.sentry.dsn= quarkus.log.sentry.in-app-packages=de.l3s.interweb +quarkus.log.sentry.ignored-exceptions-for-type=jakarta.validation.ValidationException # OpenAPI, Swagger quarkus.swagger-ui.always-include=true