use of com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException in project Plan by plan-player-analytics.
the class Identifiers method getTimestamp.
public static Optional<Long> getTimestamp(Request request) {
try {
long currentTime = System.currentTimeMillis();
long timestamp = request.getQuery().get("timestamp").map(Long::parseLong).orElse(currentTime);
if (currentTime + TimeUnit.SECONDS.toMillis(10L) < timestamp) {
return Optional.empty();
}
return Optional.of(timestamp);
} catch (NumberFormatException nonNumberTimestamp) {
throw new BadRequestException("'timestamp' was not a number: " + nonNumberTimestamp.getMessage());
}
}
Aggregations