Search in sources :

Example 11 with BadRequestException

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());
    }
}
Also used : BadRequestException(com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException)

Aggregations

BadRequestException (com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException)11 WebUser (com.djrapitops.plan.delivery.web.resolver.request.WebUser)3 JSONStorage (com.djrapitops.plan.delivery.webserver.cache.JSONStorage)3 ParseException (java.text.ParseException)3 GraphJSONCreator (com.djrapitops.plan.delivery.rendering.json.graphs.GraphJSONCreator)2 MimeType (com.djrapitops.plan.delivery.web.resolver.MimeType)2 Resolver (com.djrapitops.plan.delivery.web.resolver.Resolver)2 Response (com.djrapitops.plan.delivery.web.resolver.Response)2 Request (com.djrapitops.plan.delivery.web.resolver.request.Request)2 URIQuery (com.djrapitops.plan.delivery.web.resolver.request.URIQuery)2 DataID (com.djrapitops.plan.delivery.webserver.cache.DataID)2 ServerUUID (com.djrapitops.plan.identification.ServerUUID)2 Inject (javax.inject.Inject)2 Singleton (javax.inject.Singleton)2 DateMap (com.djrapitops.plan.delivery.domain.DateMap)1 InputFilterDto (com.djrapitops.plan.delivery.domain.datatransfer.InputFilterDto)1 InputQueryDto (com.djrapitops.plan.delivery.domain.datatransfer.InputQueryDto)1 ViewDto (com.djrapitops.plan.delivery.domain.datatransfer.ViewDto)1 Formatter (com.djrapitops.plan.delivery.formatting.Formatter)1 Formatters (com.djrapitops.plan.delivery.formatting.Formatters)1