Implement "TooManyRequests" error

This commit is contained in:
Andrea Cavalli 2021-12-24 18:50:44 +01:00
parent 6f904af461
commit 45c1bdc37b
2 changed files with 8 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package org.telegram.telegrambots.updatesreceivers;
import java.util.List;
import javax.ws.rs.core.Response.Status;
import lombok.extern.slf4j.Slf4j;
import org.telegram.telegrambots.Constants;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
@ -49,6 +50,8 @@ public class RestApi {
response.validate();
}
return Response.ok(response).build();
} catch (TooManyRequestsException e) {
return Response.status(Status.TOO_MANY_REQUESTS).build();
} catch (TelegramApiValidationException e) {
log.error(e.getLocalizedMessage(), e);
return Response.serverError().build();
@ -74,6 +77,8 @@ public class RestApi {
}
}
return Response.ok(responses).build();
} catch (TooManyRequestsException e) {
return Response.status(Status.TOO_MANY_REQUESTS).build();
} catch (TelegramApiValidationException e) {
log.error(e.getLocalizedMessage(), e);
return Response.serverError().build();

View File

@ -0,0 +1,3 @@
package org.telegram.telegrambots.updatesreceivers;
public class TooManyRequestsException extends RuntimeException {}