diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/MalformedUpdateException.java b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/MalformedUpdateException.java new file mode 100644 index 00000000..4e407abe --- /dev/null +++ b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/MalformedUpdateException.java @@ -0,0 +1,23 @@ +package org.telegram.telegrambots.updatesreceivers; + +import org.telegram.telegrambots.meta.api.objects.Update; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +public class MalformedUpdateException extends RuntimeException { + + private final Update update; + + public MalformedUpdateException(Update update, TelegramApiValidationException validationException) { + super(validationException); + this.update = update; + } + + public Update getUpdate() { + return update; + } + + @Override + public String getMessage() { + return "Malformed update"; + } +} diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/RestApi.java b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/RestApi.java index df089e02..2c5b68b0 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/RestApi.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/RestApi.java @@ -49,6 +49,9 @@ public class RestApi { response.validate(); } return Response.ok(response).build(); + } catch (MalformedUpdateException e) { + log.error("Malformed update", e.getCause());; + return Response.status(Status.BAD_REQUEST).build(); } catch (TooManyRequestsException e) { if (e.getProcessedRequestsCount().isPresent()) { return Response @@ -83,6 +86,9 @@ public class RestApi { } } return Response.ok(responses).build(); + } catch (MalformedUpdateException e) { + log.error("Malformed update", e.getCause()); + return Response.status(Status.BAD_REQUEST).build(); } catch (TooManyRequestsException e) { if (e.getProcessedRequestsCount().isPresent()) { return Response diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/TooManyRequestsException.java b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/TooManyRequestsException.java index ccc8218e..adf2117f 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/TooManyRequestsException.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/TooManyRequestsException.java @@ -27,7 +27,7 @@ public class TooManyRequestsException extends RuntimeException { } @Override - public String toString() { - return "Too many requests. " + processedRequestsCount + " requests have been processed."; + public String getMessage() { + return "Too many requests. " + processedRequestsCount + " requests have been processed"; } }