deason 7 rokov pred
rodič
commit
eb76b3df4e

+ 1 - 0
src/main/java/cn/com/qmth/examcloud/app/model/Constants.java

@@ -21,5 +21,6 @@ public interface Constants {
     String CODE_200 = "200";//成功
     String CODE_500 = "500";//失败
     String CODE_403 = "403";//认证失败
+    String CODE_404 = "404";//请求地址不存在
 
 }

+ 15 - 10
src/main/java/cn/com/qmth/examcloud/app/model/Result.java

@@ -18,8 +18,10 @@ public class Result<T> implements Serializable {
     private String desc;//描述信息
     private T data;//数据
 
-    public static String DESC_SUCCESS = "操作成功";
-    public static String DESC_FAIL = "操作失败";
+    public static String DESC_200 = "请求成功!";
+    public static String DESC_500 = "请求失败!";
+    public static String DESC_403 = "无效Token,请先登录!";
+    public static String DESC_404 = "请求地址不存在!";
 
     public Result() {
 
@@ -36,14 +38,14 @@ public class Result<T> implements Serializable {
      */
     public Result success(T data) {
         this.code = Constants.CODE_200;
-        this.desc = DESC_SUCCESS;
+        this.desc = DESC_200;
         this.data = data;
         return this;
     }
 
     public Result success() {
         this.code = Constants.CODE_200;
-        this.desc = DESC_SUCCESS;
+        this.desc = DESC_200;
         return this;
     }
 
@@ -58,16 +60,19 @@ public class Result<T> implements Serializable {
 
     public Result error() {
         this.code = Constants.CODE_500;
-        this.desc = DESC_FAIL;
+        this.desc = DESC_500;
         return this;
     }
 
-    /**
-     * 认证错误
-     */
-    public Result authError() {
+    public Result noAuthError() {
         this.code = Constants.CODE_403;
-        this.desc = "No login,Token is invalid.";
+        this.desc = DESC_403;
+        return this;
+    }
+
+    public Result noFoundError() {
+        this.code = Constants.CODE_404;
+        this.desc = DESC_404;
         return this;
     }
 

+ 5 - 2
src/main/java/cn/com/qmth/examcloud/app/utils/HttpUtils.java

@@ -21,15 +21,18 @@ public class HttpUtils {
     public static Result<String> call(Request request) throws Exception {
         Response response = HttpBuilder.client.getInstance().newCall(request).execute();
         String bodyStr = response.body().string();
-        log.debug("Http response is " + bodyStr);
         if (response.isSuccessful()) {
             //todo data
             return new Result().success(bodyStr);
         } else {
+            log.warn("Http response is " + bodyStr);
             ResBody body = new JsonMapper().fromJson(bodyStr, ResBody.class);
             if (body != null && body.getCode() != null) {
                 if (Constants.CODE_403.equals(body.getCode())) {
-                    return new Result().authError();
+                    return new Result().noAuthError();
+                }
+                if (Constants.CODE_404.equals(body.getCode())) {
+                    return new Result().noFoundError();
                 }
                 return new Result().error(body.getDesc());
             }