co.easimart.vertx.util.ErrorCodeException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vertx-util Show documentation
Show all versions of vertx-util Show documentation
Library provides utility classes for Vertx project development.
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();
}
}