feat: 优化网关异常
This commit is contained in:
parent
d43fedf5ba
commit
a5a4d4c7bb
@ -1,22 +1,24 @@
|
||||
package cn.axzo.foundation.gateway.support.exception;
|
||||
|
||||
import cn.axzo.foundation.exception.BusinessException;
|
||||
|
||||
/**
|
||||
* API不存在导致代理失败的异常.
|
||||
* <p>
|
||||
* 实施时GateServer的ExceptionResolver可以拦截该异常做特殊处理, 如统一为HTTP标准状态码返回: ModelAndView.setStatus(HttpStatus.NOT_FOUND).
|
||||
* </p>
|
||||
*/
|
||||
public class ApiNotFoundException extends RuntimeException {
|
||||
public class ApiNotFoundException extends BusinessException {
|
||||
|
||||
private static final long serialVersionUID = 8821155936941903240L;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public ApiNotFoundException(String message) {
|
||||
super(message);
|
||||
super(GateResultCode.API_NOT_FOUND.getErrorCode(), message);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public ApiNotFoundException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
super(GateResultCode.API_NOT_FOUND.getErrorCode(), message, cause);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,21 +1,23 @@
|
||||
package cn.axzo.foundation.gateway.support.exception;
|
||||
|
||||
import cn.axzo.foundation.exception.BusinessException;
|
||||
|
||||
/**
|
||||
* API未经授权访问的异常.
|
||||
* <p>
|
||||
* 实施时GateServer的ExceptionResolver可以拦截该异常做特殊处理, 如统一为HTTP标准状态码返回: ModelAndView.setStatus(HttpStatus.UNAUTHORIZED).
|
||||
* </p>
|
||||
*/
|
||||
public class ApiUnauthorizedException extends RuntimeException {
|
||||
public class ApiUnauthorizedException extends BusinessException {
|
||||
|
||||
private static final long serialVersionUID = -7679511760689237798L;
|
||||
|
||||
public ApiUnauthorizedException(String message) {
|
||||
super(message);
|
||||
super(GateResultCode.API_UNAUTHORIZED.getErrorCode(), message);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public ApiUnauthorizedException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
super(GateResultCode.API_UNAUTHORIZED.getErrorCode(), message, cause);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
package cn.axzo.foundation.gateway.support.exception;
|
||||
|
||||
import cn.axzo.foundation.result.IResultCode;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public enum GateResultCode implements IResultCode {
|
||||
API_NOT_FOUND("050", "请求路径不存在", 500),
|
||||
API_UNAUTHORIZED("051", "请求未授权", 403),
|
||||
INPUT_FIELD_ABSENT("052", "参数错误", 400),
|
||||
OUTPUT_FIELD_ABSENT("053", "返回结果错误", 500);
|
||||
|
||||
final private String code;
|
||||
|
||||
final private String message;
|
||||
|
||||
final private Integer httpCode;
|
||||
|
||||
@Override
|
||||
public String getErrorCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getErrorMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
@ -1,17 +1,19 @@
|
||||
package cn.axzo.foundation.gateway.support.exception;
|
||||
|
||||
import cn.axzo.foundation.exception.BusinessException;
|
||||
|
||||
/**
|
||||
* ParameterFilter处理输入参数时输入参数中指定的字段不存在
|
||||
*/
|
||||
public class InputFieldAbsentException extends RuntimeException {
|
||||
public class InputFieldAbsentException extends BusinessException {
|
||||
|
||||
private static final long serialVersionUID = -5646417429309513569L;
|
||||
|
||||
public InputFieldAbsentException(String message) {
|
||||
super(message);
|
||||
super(GateResultCode.INPUT_FIELD_ABSENT.getErrorCode(), message);
|
||||
}
|
||||
|
||||
public InputFieldAbsentException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
super(GateResultCode.INPUT_FIELD_ABSENT.getErrorCode(), message, cause);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,17 +1,19 @@
|
||||
package cn.axzo.foundation.gateway.support.exception;
|
||||
|
||||
import cn.axzo.foundation.exception.BusinessException;
|
||||
|
||||
/**
|
||||
* ParameterFilter处理返回对象时返回对象中指定的字段不存在
|
||||
*/
|
||||
public class OutputFieldAbsentException extends RuntimeException {
|
||||
public class OutputFieldAbsentException extends BusinessException {
|
||||
|
||||
private static final long serialVersionUID = 8830968633694688099L;
|
||||
|
||||
public OutputFieldAbsentException(String message) {
|
||||
super(message);
|
||||
super(GateResultCode.OUTPUT_FIELD_ABSENT.getErrorCode(), message);
|
||||
}
|
||||
|
||||
public OutputFieldAbsentException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
super(GateResultCode.OUTPUT_FIELD_ABSENT.getErrorCode(), message, cause);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user