Validable updates

This commit is contained in:
Andrea Cavalli 2022-01-22 01:22:59 +01:00
parent cfa4876e20
commit 1daa69cbea
3 changed files with 31 additions and 2 deletions

View File

@ -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";
}
}

View File

@ -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

View File

@ -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";
}
}