
co.easimart.vertx.http.HttpErrorCodeException Maven / Gradle / Ivy
package co.easimart.vertx.http;
import co.easimart.vertx.util.ErrorCodeException;
import io.netty.handler.codec.http.HttpResponseStatus;
/**
* ErrorCodeException which has http response status.
*/
public class HttpErrorCodeException extends ErrorCodeException {
private final HttpResponseStatus status;
public HttpErrorCodeException(HttpResponseStatus status, int errorCode) {
this(null, status, errorCode, null);
}
public HttpErrorCodeException(HttpResponseStatus status, int errorCode, String reason) {
this(null, status, errorCode, reason);
}
public HttpErrorCodeException(HttpResponseStatus status, ErrorCodeException ece) {
this(ece.getCause(), status, ece.errorCode(), ece.reason());
}
public HttpErrorCodeException(Throwable cause, HttpResponseStatus status, int errorCode) {
this(cause, status, errorCode, null);
}
public HttpErrorCodeException(ErrorCodeException ece) {
super(ece.getCause(), ece.errorCode(), ece.reason());
if (ece.errorCode() == CommonCode.BAD_ARGUMENT.code()) {
this.status = HttpResponseStatus.BAD_REQUEST;
} else if (ece.errorCode() == CommonCode.UNAUTHORIZED.code()) {
this.status = HttpResponseStatus.UNAUTHORIZED;
} else if (ece.errorCode() == CommonCode.FORBIDDEN.code()) {
this.status = HttpResponseStatus.FORBIDDEN;
} else if (ece.errorCode() == CommonCode.NOT_FOUND.code()) {
this.status = HttpResponseStatus.NOT_FOUND;
} else if (ece.errorCode() == CommonCode.TOO_LARGE.code()) {
this.status = HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE;
} else if (ece.errorCode() == CommonCode.UNPROCESSED.code()) {
this.status = HttpResponseStatus.UNPROCESSABLE_ENTITY;
} else {
this.status = HttpResponseStatus.FORBIDDEN;
}
}
public HttpErrorCodeException(Throwable cause, HttpResponseStatus status, String reason) {
this(cause, status, status.code() * -1, reason);
}
public HttpErrorCodeException(Throwable cause, HttpResponseStatus status, int errorCode, String reason) {
super(cause, errorCode, reason);
this.status = status;
}
public HttpResponseStatus getHttpStatus() {
return this.status;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy