mirror of
https://github.com/vran-dev/databasir.git
synced 2025-08-08 18:10:26 +08:00
feat: show error message when oauth callback error (#34)
* feat: show error message when oauth callback error * fix: checkstyle
This commit is contained in:
@@ -26,7 +26,8 @@ public enum DomainErrors implements DatabasirErrors {
|
||||
ORIGIN_PASSWORD_NOT_CORRECT("A_10011", "原密码不正确"),
|
||||
INVALID_CRON_EXPRESSION("A_10012", "不合法的 cron 表达式"),
|
||||
REGISTRATION_ID_DUPLICATE("A_10013", "应用注册 ID 不能重复"),
|
||||
MISS_REQUIRED_PARAMETERS("A_10014", "缺少必填参数");
|
||||
REGISTRATION_ID_NOT_FOUND("A_10014", "应用 ID 不存在"),
|
||||
MISS_REQUIRED_PARAMETERS("A_10015", "缺少必填参数");
|
||||
|
||||
private final String errCode;
|
||||
|
||||
@@ -43,4 +44,8 @@ public enum DomainErrors implements DatabasirErrors {
|
||||
public DatabasirException exception(String message, Throwable origin) {
|
||||
return new DatabasirException(this, message, origin);
|
||||
}
|
||||
|
||||
public DatabasirException exception(String s) {
|
||||
return exception(s, (Throwable) null);
|
||||
}
|
||||
}
|
||||
|
@@ -1,19 +1,24 @@
|
||||
package com.databasir.core.domain.app.exception;
|
||||
|
||||
import com.databasir.common.DatabasirException;
|
||||
import lombok.Getter;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
|
||||
@Getter
|
||||
public class DatabasirAuthenticationException extends AuthenticationException {
|
||||
|
||||
private final DatabasirException databasirException;
|
||||
|
||||
public DatabasirAuthenticationException(DatabasirException databasirException) {
|
||||
super(databasirException.getErrMessage(), databasirException);
|
||||
this.databasirException = databasirException;
|
||||
}
|
||||
|
||||
public DatabasirAuthenticationException(String msg) {
|
||||
super(msg);
|
||||
public String getErrMessage() {
|
||||
return databasirException.getErrMessage();
|
||||
}
|
||||
|
||||
public DatabasirAuthenticationException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
public String getErrCode() {
|
||||
return databasirException.getErrCode();
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.databasir.core.domain.app.handler;
|
||||
|
||||
import com.databasir.core.domain.app.exception.DatabasirAuthenticationException;
|
||||
import com.databasir.dao.impl.OauthAppDao;
|
||||
import com.databasir.dao.tables.pojos.OauthAppPojo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -8,6 +9,8 @@ import org.springframework.stereotype.Component;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.databasir.core.domain.DomainErrors.REGISTRATION_ID_NOT_FOUND;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class OpenAuthHandlers {
|
||||
@@ -26,7 +29,11 @@ public class OpenAuthHandlers {
|
||||
}
|
||||
|
||||
public OAuthProcessResult process(String registrationId, Map<String, String[]> parameters) {
|
||||
OauthAppPojo app = oauthAppDao.selectByRegistrationId(registrationId);
|
||||
OauthAppPojo app = oauthAppDao.selectOptionByRegistrationId(registrationId)
|
||||
.orElseThrow(() -> {
|
||||
var bizErr = REGISTRATION_ID_NOT_FOUND.exception("应用 ID [" + registrationId + "] 不存在");
|
||||
return new DatabasirAuthenticationException(bizErr);
|
||||
});
|
||||
return handlers.stream()
|
||||
.filter(handler -> handler.support(app.getAppType()))
|
||||
.findFirst()
|
||||
|
Reference in New Issue
Block a user