Validable updates
This commit is contained in:
parent
cfa4876e20
commit
1daa69cbea
@ -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";
|
||||||
|
}
|
||||||
|
}
|
@ -49,6 +49,9 @@ public class RestApi {
|
|||||||
response.validate();
|
response.validate();
|
||||||
}
|
}
|
||||||
return Response.ok(response).build();
|
return Response.ok(response).build();
|
||||||
|
} catch (MalformedUpdateException e) {
|
||||||
|
log.error("Malformed update", e.getCause());;
|
||||||
|
return Response.status(Status.BAD_REQUEST).build();
|
||||||
} catch (TooManyRequestsException e) {
|
} catch (TooManyRequestsException e) {
|
||||||
if (e.getProcessedRequestsCount().isPresent()) {
|
if (e.getProcessedRequestsCount().isPresent()) {
|
||||||
return Response
|
return Response
|
||||||
@ -83,6 +86,9 @@ public class RestApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Response.ok(responses).build();
|
return Response.ok(responses).build();
|
||||||
|
} catch (MalformedUpdateException e) {
|
||||||
|
log.error("Malformed update", e.getCause());
|
||||||
|
return Response.status(Status.BAD_REQUEST).build();
|
||||||
} catch (TooManyRequestsException e) {
|
} catch (TooManyRequestsException e) {
|
||||||
if (e.getProcessedRequestsCount().isPresent()) {
|
if (e.getProcessedRequestsCount().isPresent()) {
|
||||||
return Response
|
return Response
|
||||||
|
@ -27,7 +27,7 @@ public class TooManyRequestsException extends RuntimeException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String getMessage() {
|
||||||
return "Too many requests. " + processedRequestsCount + " requests have been processed.";
|
return "Too many requests. " + processedRequestsCount + " requests have been processed";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user