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

co.easimart.vertx.util.ErrorCodeException Maven / Gradle / Ivy

The newest version!
package co.easimart.vertx.util;

/**
 * Exception with error code and reason
 */
public class ErrorCodeException extends RuntimeException {

    public enum CommonCode {
        BAD_ARGUMENT(-400),
        UNAUTHORIZED(-401),
        FORBIDDEN(-403),
        NOT_FOUND(-404),
        TOO_LARGE(-413),
        UNPROCESSED(-422);

        private final int errorCode;

        CommonCode(int errorCode) {
            this.errorCode = errorCode;
        }

        public int code() {
            return this.errorCode;
        }
    }

    private final int errorCode;
    private final String reason;

    public ErrorCodeException(int errorCode) {
        this(null, errorCode);
    }

    public ErrorCodeException(int errorCode, String reason) {
        this(null, errorCode, reason);
    }

    public ErrorCodeException(Throwable cause, int errorCode) {
        this(cause, errorCode, null);
    }

    public ErrorCodeException(Throwable cause, int errorCode, String reason) {
        super(cause);
        this.errorCode = errorCode;
        this.reason = reason;
    }

    public int errorCode() {
        return this.errorCode;
    }

    public String reason() {
        return this.reason;
    }

    @Override
    public String getMessage() {
        return reason();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy