sac/sf-vertx/src/main/java/com/sf/vertx/exception/ServiceException.java
2024-05-24 18:54:30 +08:00

39 lines
977 B
Java

package com.sf.vertx.exception;
import com.sf.vertx.enums.GatewayError;
import io.netty.handler.codec.http.HttpResponseStatus;
/**
* 业务异常
*/
public class ServiceException extends RuntimeException {
private static final long serialVersionUID = 7975954645547803572L;
private final int statusCode;
private final String payload;
public ServiceException() {
this(GatewayError.DEFAULT_SERVICE_ERROR);
}
public ServiceException(GatewayError gatewayError, String payload) {
this(gatewayError.getCode(), payload, null);
}
public ServiceException(GatewayError gatewayError) {
this(gatewayError.getCode(), gatewayError.getReasonPhrase(), null);
}
private ServiceException(int statusCode, String payload, Throwable cause) {
super("(" + statusCode + ")" + payload, cause, false, false);
this.statusCode = statusCode;
this.payload = payload;
}
public int getStatusCode() {
return statusCode;
}
public String getPayload() {
return payload;
}
}