Skip to content

Commit

Permalink
#48 refactor some exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
gavin2lee committed Feb 24, 2021
1 parent b8812fc commit 0ca468c
Show file tree
Hide file tree
Showing 30 changed files with 179 additions and 931 deletions.
16 changes: 3 additions & 13 deletions src/main/java/com/webank/taskman/base/BaseEntity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.webank.taskman.base;

import java.util.Date;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.webank.taskman.commons.AuthenticationContextHolder;

import java.util.Date;

public class BaseEntity<T> {
public class BaseEntity {

private String createdBy;

Expand Down Expand Up @@ -61,13 +60,4 @@ public Integer getDelFlag() {
public void setDelFlag(Integer delFlag) {
this.delFlag = delFlag;
}

// public void setCurrenUserName(BaseEntity entity, String Id) {
// // if(StringUtils.isEmpty(Id)){
// // entity.setCreatedBy(AuthenticationContextHolder.getCurrentUsername());
// // }
// entity.setCreatedBy(AuthenticationContextHolder.getCurrentUsername());
// entity.setUpdatedBy(AuthenticationContextHolder.getCurrentUsername());
//
// }
}
83 changes: 13 additions & 70 deletions src/main/java/com/webank/taskman/base/JsonResponse.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package com.webank.taskman.base;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.StringJoiner;

import com.webank.taskman.constant.BizCodeEnum;
import com.webank.taskman.constant.StatusCodeEnum;

public class JsonResponse implements Serializable {
/**
Expand All @@ -17,10 +12,11 @@ public class JsonResponse implements Serializable {

private String status;
private String message;
private Integer code;
private String codeMessage;
private Object data;

public JsonResponse() {
}

public String getStatus() {
return status;
}
Expand All @@ -42,82 +38,29 @@ public Object getData() {
}

public void setData(Object data) {
this.data = null != data ? data : (Object) new ArrayList<Object>();
}

public Integer getCode() {
return code;
}

public void setCode(Integer code) {
this.code = code;
}

public String getCodeMessage() {
return codeMessage;
}

public void setCodeMessage(String codeMessage) {
this.codeMessage = codeMessage;
this.data = data;
}

public JsonResponse withData(Object data) {
setData(data);
return this;
}

public JsonResponse() {
}

public JsonResponse(String status, String message, Integer code, String codeMessage, Object data) {
this.status = status;
this.message = message;
this.code = code;
this.codeMessage = codeMessage;
setData(data);
}

public static JsonResponse okay() {
return new JsonResponse(STATUS_OK, "Success", 200, "", null);
JsonResponse result = new JsonResponse();
result.setStatus(STATUS_OK);
result.setMessage("Success");
return result;
}

public static JsonResponse okayWithData(Object data) {
return okay().withData(data);
}

public static JsonResponse customError(String errorMessage) {
return new JsonResponse(STATUS_ERROR, errorMessage, null, null, null);
}

public static JsonResponse customError(BizCodeEnum bizCodeEnum, Object data) {
return new JsonResponse(STATUS_ERROR, null, bizCodeEnum.getCode(), bizCodeEnum.getMessage(), data);
}

public static JsonResponse customError(Integer code, String codeMessage, Object data) {
return new JsonResponse(STATUS_ERROR, null, code, codeMessage, data);
}

public static JsonResponse customError(Integer code, String codeMessage, String errorMessage, Object data) {
return new JsonResponse(STATUS_ERROR, codeMessage, code, errorMessage, data);
}

public static JsonResponse customError(BizCodeEnum bizCodeEnum, String errorMessage) {
return new JsonResponse(STATUS_ERROR, bizCodeEnum.getMessage(), bizCodeEnum.getCode(), errorMessage, null);
}

public static JsonResponse customError(BizCodeEnum bizCodeEnum, String message, String errorMessage) {
return new JsonResponse(STATUS_ERROR, message, bizCodeEnum.getCode(), errorMessage, null);
}

public static JsonResponse customError(StatusCodeEnum statusCodeEnum) {
return new JsonResponse(STATUS_ERROR, statusCodeEnum.getMessage(), Integer.valueOf(statusCodeEnum.getCode()),
statusCodeEnum.getMessage(), null);
}

@Override
public String toString() {
return new StringJoiner(", ", JsonResponse.class.getSimpleName() + "[", "]").add("status='" + status + "'")
.add("message='" + message + "'").add("code=" + code).add("codeMessage='" + codeMessage + "'")
.add("data=" + data.getClass().getTypeName()).toString();
public static JsonResponse error(String errorMessage) {
JsonResponse result = new JsonResponse();
result.setStatus(STATUS_ERROR);
result.setMessage(errorMessage);
return result;
}
}
130 changes: 0 additions & 130 deletions src/main/java/com/webank/taskman/commons/TaskmanException.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.webank.taskman.commons;

import com.webank.taskman.constant.StatusCodeEnum;

public class TaskmanRuntimeException extends RuntimeException {

/**
Expand All @@ -24,23 +22,12 @@ public TaskmanRuntimeException(String message, Throwable cause) {
this.applyMessage = true;
}

public TaskmanRuntimeException(StatusCodeEnum errorCode) {
this.errorCode = errorCode.getCode();
this.messageKey = errorCode.getMessage();
this.applyMessage = true;
}
public TaskmanRuntimeException(StatusCodeEnum errorCode, String message) {
super(message);
this.errorCode = errorCode.getCode();
this.applyMessage = true;
}

public TaskmanRuntimeException(String errorCode, String message, Object... objects) {
this(errorCode, null, message, null, false, objects);
}

private TaskmanRuntimeException(String errorCode, String messageKey, String message, Throwable cause,
boolean applyMessage, Object... objects) {
boolean applyMessage, Object... objects) {
super(message, cause);
this.errorCode = errorCode;
this.messageKey = messageKey;
Expand Down
34 changes: 0 additions & 34 deletions src/main/java/com/webank/taskman/config/Knife4jConfiguration.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public MybatisPlusInterceptor mybatisPlusInterceptor() {
return interceptor;
}

@SuppressWarnings("deprecation")
@Bean
public ConfigurationCustomizer configurationCustomizer() {
return configuration -> configuration.setUseDeprecatedExecutor(false);
Expand Down
25 changes: 0 additions & 25 deletions src/main/java/com/webank/taskman/constant/BizCodeEnum.java

This file was deleted.

Loading

0 comments on commit 0ca468c

Please sign in to comment.