All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.flightstats.http.HttpException Maven / Gradle / Ivy

package com.flightstats.http;

import lombok.EqualsAndHashCode;
import lombok.Value;
import lombok.experimental.Delegate;

import java.net.HttpURLConnection;

import static java.net.HttpURLConnection.*;

@Value
@EqualsAndHashCode(callSuper = false)
public class HttpException extends RuntimeException {

    @Delegate
    Details details;

    public HttpException(Details details, Exception e) {
        super(e);
        this.details = details;
    }

    public HttpException(Details details) {
        this.details = details;
    }

    public static HttpException invalidRequest(String message) {
        return new HttpException(new Details(HTTP_BAD_REQUEST, message));
    }

    public static HttpException unprocessableEntity(String message) {
        return new HttpException(new Details(422, message));
    }

    public static HttpException conflict(String message) {
        return new HttpException(new Details(HTTP_CONFLICT, message));
    }

    public static HttpException notFound(String message) {
        return new HttpException(new Details(HTTP_NOT_FOUND, message));
    }

    public static HttpException invalidRequest(String message, Exception e) {
        return new HttpException(new Details(HTTP_BAD_REQUEST, message), e);
    }

    public static HttpException forbidden(String message) {
        return new HttpException(new Details(HttpURLConnection.HTTP_FORBIDDEN, message));
    }

    @Value
    public static class Details {
        int statusCode;
        String message;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy