Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] [Seatunnel-web] Validation messages are wrong #186

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ private Result(SeatunnelException e) {
this.data = null;
}

private Result(int code, String msg) {
this.code = code;
this.msg = msg;
this.data = null;
}

public static <T> Result<T> success() {
return new Result<>();
}
Expand All @@ -72,11 +78,16 @@ public static <T> Result<T> failure(SeatunnelErrorEnum errorEnum, String... mess
return result;
}

public static <T> Result<T> getFailure(SeatunnelException e) {
public static <T> Result<T> failure(SeatunnelException e) {
Result<T> result = new Result<>(e);
return result;
}

public static <T> Result<T> failure(int code, String msg) {
Result<T> result = new Result<>(code, msg);
return result;
}

public boolean isSuccess() {
return OK.getCode() == this.code;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,21 @@ public class GlobalExceptionHandler {

@ExceptionHandler(value = SeatunnelException.class)
private Result<String> portalExceptionHandler(SeatunnelException e) {
logError(e);

// final SeatunnelException seatunnelException =
// Optional.ofNullable(e)
//
// .orElse(SeatunnelException.newInstance(SeatunnelErrorEnum.UNKNOWN));

final String message = e.getMessage();
final SeatunnelErrorEnum errorEnum = e.getErrorEnum();

return Result.failure(errorEnum, message);
logDebug(e);
return Result.failure(e);
}

@ExceptionHandler(value = DataSourcePluginException.class)
private Result<String> dsHandler(DataSourcePluginException e) {
logError(e);
final String message = e.getMessage();
return Result.failure(SeatunnelErrorEnum.INVALID_DATASOURCE, e.getMessage());
return Result.failure(
SeatunnelErrorEnum.INVALID_DATASOURCE.getCode(),
SeatunnelErrorEnum.INVALID_DATASOURCE.getMsg() + ". " + e.getMessage());
}

@ExceptionHandler(value = MissingServletRequestParameterException.class)
private Result<String> missParam(MissingServletRequestParameterException e) {
logError(e);
logDebug(e);
return Result.failure(SeatunnelErrorEnum.MISSING_PARAM, e.getParameterName());
}

Expand All @@ -70,22 +62,30 @@ private Result<String> illegalStateExceptionHandler(IllegalStateException e) {

@ExceptionHandler(value = ExpiredJwtException.class)
private Result<String> expiredJwtException(ExpiredJwtException e) {
logError(e);
logDebug(e);
return Result.failure(SeatunnelErrorEnum.TOKEN_ILLEGAL, e.getMessage());
}

@ExceptionHandler(value = Exception.class)
private Result<String> exceptionHandler(Exception e) {
logError(e);
return Result.failure(SeatunnelErrorEnum.UNKNOWN, e.getMessage());
return Result.failure(
SeatunnelErrorEnum.UNKNOWN.getCode(),
SeatunnelErrorEnum.UNKNOWN.getMsg() + ". " + e.getMessage());
}

private void logError(Throwable throwable) {
log.error(throwable.getMessage(), throwable);
}

private void logDebug(Throwable throwable) {
if (log.isDebugEnabled()) {
log.debug(throwable.getMessage(), throwable);
}
}

@ExceptionHandler(value = ParamValidationException.class)
private Result<String> paramValidationHandler(SeatunnelException e) {
return Result.getFailure(e);
return Result.failure(e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public enum SeatunnelErrorEnum {
99996, "unsupported operation", "This operation [%s] is not supported now."),
HTTP_REQUEST_FAILED(99997, "http request failed", "Http request failed, url is %s"),
ILLEGAL_STATE(99998, "illegal state", "%s"),
UNKNOWN(99999, "unknown exception", "Unknown exception"),
UNKNOWN(99999, "Unknown exception", "Unknown exception"),

UNSUPPORTED_CONNECTOR_TYPE(
30000,
Expand Down Expand Up @@ -124,7 +124,7 @@ public enum SeatunnelErrorEnum {
1600000,
"datasource can not be delete because it used by task",
"datasource can not be delete because it used by task"),
INVALID_DATASOURCE(-70001, "Datasource [{0}] invalid", "datasource [{0}] invalid"),
INVALID_DATASOURCE(-70001, "Datasource invalid", "datasource [{0}] invalid"),
MISSING_PARAM(1777000, "param miss [{0}]", "param miss [{0}]"),
PARAM_CAN_NOT_BE_NULL(60018, "", "param [%s] can not be null or empty"),
INVALID_PARAM(60019, "", "param [%s] is invalid. %s"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.seatunnel.app.domain.response.PageInfo;
import org.apache.seatunnel.app.domain.response.datasource.DatasourceDetailRes;
import org.apache.seatunnel.app.domain.response.datasource.DatasourceRes;
import org.apache.seatunnel.server.common.SeatunnelErrorEnum;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -121,7 +122,8 @@ public void createDatasource_shouldFailIfDuplicate() {
seatunnelDatasourceControllerWrapper.getFakeSourceDatasourceReq(datasourceName);
Result<String> result = seatunnelDatasourceControllerWrapper.createDatasource(req);
assertTrue(result.isFailed());
assertEquals(60004, result.getCode());
assertEquals(SeatunnelErrorEnum.DATASOURCE_NAME_ALREADY_EXISTS.getCode(), result.getCode());
assertEquals("datasource [" + datasourceName + "] already exists", result.getMsg());
}

@AfterAll
Expand Down
Loading