Skip to content

Commit

Permalink
add error type to error displaying
Browse files Browse the repository at this point in the history
  • Loading branch information
Pil0tXia committed Oct 19, 2023
1 parent 1efb961 commit 4d877ee
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ public class ConfigConst {
// Open-API
public static final String HTTP_PREFIX = "http://";
public static final String HTTPS_PREFIX = "https://";

// common
/**
* colon with space
*/
public static final String COLON = ": ";

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.eventmesh.admin.enums;

import static org.apache.eventmesh.admin.common.ConfigConst.COLON;

import org.springframework.http.HttpStatus;

import lombok.Getter;
Expand Down Expand Up @@ -62,6 +64,12 @@ public enum Errors {
this.desc = desc;
}

@Override
public String toString() {
return name() + " of " + type + COLON + desc;
}

@Getter
public enum Types {

SUCCESS("Operation Success"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.eventmesh.admin.exception;

import static org.apache.eventmesh.admin.common.ConfigConst.COLON;

import org.apache.eventmesh.admin.enums.Errors;
import org.apache.eventmesh.admin.utils.ExceptionUtils;

Expand All @@ -31,11 +33,6 @@ public class BaseException extends RuntimeException {

private static final long serialVersionUID = 3509261993355721168L;

/**
* colon with space
*/
public static final String COLON = ": ";

private Errors errors;

public BaseException(String message) {
Expand All @@ -46,12 +43,12 @@ public BaseException(String message) {
* Customized error reporting using enums and exceptions
*/
public BaseException(Errors errors, Throwable cause) {
super(errors.getType() + COLON + ExceptionUtils.trimDesc(errors.getDesc()) + COLON + cause.getMessage(), cause);
super(ExceptionUtils.trimDesc(errors.toString()) + COLON + cause.getMessage(), cause);
this.errors = errors;
}

public BaseException(Errors errors) {
super(errors.getDesc());
super(errors.toString());
this.errors = errors;
}
}

0 comments on commit 4d877ee

Please sign in to comment.