houzhongjian
2025-03-06 741870d9ecf94d63a9c08e923a80f70f04812b03
增加错误信息捕获
已修改3个文件
87 ■■■■ 文件已修改
iailab-plat-sdk/pom.xml 50 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-plat-sdk/src/main/java/com/iailab/sdk/auth/client/IailabAuthClient.java 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-plat-sdk/src/main/java/com/iailab/sdk/util/http/HttpClientFactory.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-plat-sdk/pom.xml
@@ -55,17 +55,49 @@
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.3.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                </configuration>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.6.0</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptorRefs>
                                <!-- 使用预定义的打包方式:将所有内容合并到 JAR 中 -->
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                            <!-- 指定主类 -->
                            <archive>
                                <manifest>
                                    <mainClass>com.iailab.sdk.IailabPlatSdkMain</mainClass>
                                </manifest>
                            </archive>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
<!--    <build>-->
<!--        <plugins>-->
<!--            <plugin>-->
<!--                <groupId>org.apache.maven.plugins</groupId>-->
<!--                <artifactId>maven-jar-plugin</artifactId>-->
<!--                <version>3.3.0</version>-->
<!--                <configuration>-->
<!--                    <archive>-->
<!--                        <manifest>-->
<!--                            <addClasspath>true</addClasspath>-->
<!--                            <classpathPrefix>lib/</classpathPrefix>-->
<!--                            <mainClass>com.iailab.sdk.IailabPlatSdkMain</mainClass>-->
<!--                        </manifest>-->
<!--                    </archive>-->
<!--                </configuration>-->
<!--            </plugin>-->
<!--        </plugins>-->
<!--    </build>-->
</project>
iailab-plat-sdk/src/main/java/com/iailab/sdk/auth/client/IailabAuthClient.java
@@ -1,9 +1,8 @@
package com.iailab.sdk.auth.client;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.iailab.sdk.auth.client.dto.TokenDTO;
import com.iailab.sdk.auth.client.vo.AuthLoginReqVO;
import com.iailab.sdk.auth.config.AuthProperties;
import com.iailab.sdk.auth.constants.ErrorCodeConstants;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
@@ -16,9 +15,7 @@
import java.nio.charset.StandardCharsets;
import java.util.*;
import static com.iailab.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST;
import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.iailab.sdk.auth.enums.ErrorCodeConstants.*;
/**
 * @author Houzhongjian
@@ -72,13 +69,22 @@
                new HttpEntity<>(headers),
                new ParameterizedTypeReference<Map<String, Object>>() {
                });
        Map<String, Object> authMap = exchange.getBody();
        if(AUTH_BAD_CREDENTIALS.getCode().equals(authMap.get("code"))) {
            throw exception(AUTH_BAD_CREDENTIALS);
        } else if(AUTH_LOGIN_BAD_CREDENTIALS.getCode().equals(authMap.get("code"))) {
            throw exception(AUTH_LOGIN_BAD_CREDENTIALS);
        }
        Assert.isTrue(exchange.getStatusCode().is2xxSuccessful(), "响应必须是 200 成功");
        Map<String, Object> authMap = exchange.getBody();
        Object code = authMap.get("code");
        if(ErrorCodeConstants.AUTH_BAD_CREDENTIALS.getCode().equals(code)) {
            throw exception(ErrorCodeConstants.AUTH_BAD_CREDENTIALS);
        } else if(ErrorCodeConstants.AUTH_LOGIN_BAD_CREDENTIALS.getCode().equals(code)) {
            throw exception(ErrorCodeConstants.AUTH_LOGIN_BAD_CREDENTIALS);
        } else if(ErrorCodeConstants.OAUTH2_CLIENT_REDIRECT_URI_NOT_MATCH.getCode().equals(code)) {
            throw exception(ErrorCodeConstants.OAUTH2_CLIENT_REDIRECT_URI_NOT_MATCH);
        } else if(ErrorCodeConstants.OAUTH2_CLIENT_CLIENT_SECRET_ERROR.getCode().equals(code)) {
            throw exception(ErrorCodeConstants.OAUTH2_CLIENT_CLIENT_SECRET_ERROR);
        } else if(ErrorCodeConstants.OAUTH2_CLIENT_NOT_EXISTS.getCode().equals(code)) {
            throw exception(ErrorCodeConstants.OAUTH2_CLIENT_NOT_EXISTS);
        } else if(ErrorCodeConstants.OAUTH2_CLIENT_DISABLE.getCode().equals(code)) {
            throw exception(ErrorCodeConstants.OAUTH2_CLIENT_DISABLE);
        }
        accessToken = authMap.get("access_token").toString();
        refreshToken = authMap.get("refresh_token").toString();
        expireTime = Long.valueOf(authMap.get("expires_time").toString());
@@ -107,7 +113,7 @@
            if (code == 401) {
                authenticate();
            } else {
                throw exception(AUTH_REFRESH_TOKEN_ERROR);
                throw exception(ErrorCodeConstants.AUTH_REFRESH_TOKEN_ERROR);
            }
        } else {
            accessToken = authMap.get("access_token").toString();
@@ -131,10 +137,9 @@
        System.out.println(response);
        TokenDTO authTokenDTO = new TokenDTO();
        Map<String, Object> authMap = (Map<String, Object>)response.getBody();
        Map<String, Object> tokenData = (Map<String, Object>)authMap.get("data");
        authTokenDTO.setAccessToken(tokenData.get("accessToken").toString());
        authTokenDTO.setRefreshToken(tokenData.get("refreshToken").toString());
        authTokenDTO.setExpiresTime(Long.valueOf(tokenData.get("expiresTime").toString()));
        authTokenDTO.setAccessToken(authMap.get("access_token").toString());
        authTokenDTO.setRefreshToken(authMap.get("refresh_token").toString());
        authTokenDTO.setExpiresTime(Long.valueOf(authMap.get("expires_time").toString()));
        return authTokenDTO;
    }
iailab-plat-sdk/src/main/java/com/iailab/sdk/util/http/HttpClientFactory.java
@@ -149,7 +149,7 @@
        return null;
    }
    private static   void safeClose(Closeable closeable,String errMsg){
    private static void safeClose(Closeable closeable,String errMsg){
        try{
            if(closeable!=null)
            closeable.close();