Explorar o código

修改starter-api中内部错误码定义,并在文档中详细陈列出来

Signed-off-by: luoshi <luoshi@qmth.com.cn>
luoshi hai 1 ano
pai
achega
5ed9802aae

+ 1 - 1
core-security/src/main/java/com/qmth/boot/core/security/exception/AuthorizationException.java

@@ -23,7 +23,7 @@ public class AuthorizationException extends RuntimeException {
 
     public static AuthorizationException NO_PERMISSION = new AuthorizationException(401008, "no permission");
 
-    public static AuthorizationException SERVICE_NOT_FOUND = new AuthorizationException(401010,
+    public static AuthorizationException SERVICE_NOT_FOUND = new AuthorizationException(401009,
             "authorization service not found");
 
     public AuthorizationException(int code, String message) {

+ 5 - 5
starter-api/src/main/java/com/qmth/boot/api/exception/DefaultExceptionEnum.java

@@ -8,17 +8,17 @@ import org.springframework.http.HttpStatus;
  */
 public enum DefaultExceptionEnum {
 
-    HEADER_INVALID(HttpStatus.BAD_REQUEST, 400001, "header field invalid"),
-    REQUEST_PARAMETER_INVALID(HttpStatus.BAD_REQUEST, 400002, "request parameter invalid"),
+    REQUEST_PARAMETER_INVALID(HttpStatus.BAD_REQUEST, 400000, "request parameter invalid"),
+    HEADER_PLATFORM_INVALID(HttpStatus.BAD_REQUEST, 400001, "header platform invalid"),
+    HEADER_DEVICEID_INVALID(HttpStatus.BAD_REQUEST, 400002, "header deviceId invalid"),
     ACCESS_FORBIDDEN(HttpStatus.FORBIDDEN, 403000, "access forbidden"),
     PLATFORM_FORBIDDEN(HttpStatus.FORBIDDEN, 403001, "platform not allowed"),
     IP_FORBIDDEN(HttpStatus.FORBIDDEN, 403002, "ip not allowed"),
-    AUTHORIZATION_ERROR(HttpStatus.UNAUTHORIZED, 401001, "authorization error"),
-    AUTHORIZATION_FAILE(HttpStatus.UNAUTHORIZED, 401002, "authorization faile"),
+    AUTHORIZATION_ERROR(HttpStatus.UNAUTHORIZED, 401000, "authorization error"),
     COMMON_EXCEPTION(HttpStatus.INTERNAL_SERVER_ERROR, 500000, "internal server error"),
     REENTRANT_EXCEPTION(HttpStatus.SERVICE_UNAVAILABLE, 503001, "service unavailable"),
     RATE_LIMITED(HttpStatus.SERVICE_UNAVAILABLE, 503002, "request rate limited"),
-    RESOURCE_NOT_FOUND(HttpStatus.NOT_FOUND, 404001, "resource not found");
+    RESOURCE_NOT_FOUND(HttpStatus.NOT_FOUND, 404000, "resource not found");
 
     private HttpStatus status;
 

+ 1 - 1
starter-api/src/main/java/com/qmth/boot/api/interceptor/impl/AuthorizationInterceptor.java

@@ -52,7 +52,7 @@ public class AuthorizationInterceptor extends AbstractInterceptor implements Log
                 MDC.put(MDC_CALLER, entity.getLogName());
             } catch (AuthorizationException ae) {
                 log.warn("Authorization faile: path={}, reason={}", request.getServletPath(), ae.getMessage());
-                throw DefaultExceptionEnum.AUTHORIZATION_FAILE.exception(ae.getCode(), ae.getMessage());
+                throw DefaultExceptionEnum.AUTHORIZATION_ERROR.exception(ae.getCode(), ae.getMessage());
             } catch (Exception e) {
                 log.warn("Authorization error: path={}, reason={}", request.getServletPath(), e.getMessage());
                 throw DefaultExceptionEnum.AUTHORIZATION_ERROR.exception(e.getMessage());

+ 2 - 2
starter-api/src/main/java/com/qmth/boot/api/interceptor/impl/ValveInterceptor.java

@@ -47,10 +47,10 @@ public class ValveInterceptor extends AbstractInterceptor implements ApiConstant
         if (config.isStrict()) {
             // 严格模式platform和deviceId必须存在
             if (platform == null) {
-                throw DefaultExceptionEnum.HEADER_INVALID.exception("platform is required");
+                throw DefaultExceptionEnum.HEADER_PLATFORM_INVALID.exception();
             }
             if (deviceId == null) {
-                throw DefaultExceptionEnum.HEADER_INVALID.exception("deviceId is required");
+                throw DefaultExceptionEnum.HEADER_DEVICEID_INVALID.exception();
             }
             // 匹配指定允许的platform
             validatePlatform(request, platform, config);