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

io.github.yawenok.apns.http2.enums.response.ResponseError Maven / Gradle / Ivy

package io.github.yawenok.apns.http2.enums.response;

import java.util.HashMap;
import java.util.Map;

public enum ResponseError {
    BadCollapseId(400, "BadCollapseId"),
    BadDeviceToken(400, "BadDeviceToken"),
    BadExpirationDate(400, "BadExpirationDate"),
    BadMessageId(400, "BadMessageId"),
    BadPriority(400, "BadPriority"),
    BadTopic(400, "BadTopic"),
    DeviceTokenNotForTopic(400, "DeviceTokenNotForTopic"),
    DuplicateHeaders(400, "DuplicateHeaders"),
    IdleTimeout(400, "IdleTimeout"),
    MissingDeviceToken(400, "MissingDeviceToken"),
    MissingTopic(400, "MissingTopic"),
    PayloadEmpty(400, "PayloadEmpty"),
    TopicDisallowed(400, "TopicDisallowed"),
    BadCertificate(403, "BadCertificate"),
    BadCertificateEnvironment(403, "BadCertificateEnvironment"),
    ExpiredProviderToken(403, "ExpiredProviderToken"),
    Forbidden(403, "Forbidden"),
    InvalidProviderToken(403, "InvalidProviderToken"),
    MissingProviderToken(403, "MissingProviderToken"),
    BadPath(404, "BadPath"),
    MethodNotAllowed(405, "MethodNotAllowed"),
    Unregistered(410, "Unregistered"),
    PayloadTooLarge(413, "PayloadTooLarge"),
    TooManyProviderTokenUpdates(429, "TooManyProviderTokenUpdates"),
    TooManyRequests(429, "TooManyRequests"),
    InternalServerError(500, "InternalServerError"),
    ServiceUnavailable(503, "ServiceUnavailable"),
    Shutdown(503, "Shutdown");

    private final int code;
    private final String error;

    ResponseError(int code, String error) {
        this.code = code;
        this.error = error;
    }

    public int getCode() {
        return code;
    }

    public String getError() {
        return error;
    }

    private static Map> codeMap = new HashMap<>();
    static {
        for (final ResponseError responseError : ResponseError.values()) {
            Map errorMap = codeMap.get(responseError.getCode());
            if (errorMap == null) {
                errorMap = new HashMap<>();
            }
            errorMap.put(responseError.getError().toLowerCase(), responseError);
            codeMap.put(responseError.getCode(), errorMap);
        }
    }

    public static ResponseError getResponseError(int code, String error) {
        Map errorMap = codeMap.get(code);
        if (errorMap != null) {
            return errorMap.get(error.toLowerCase());
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy