diff --git a/src/backend/ci/core/openapi/api-openapi/src/main/kotlin/com/tencent/devops/openapi/api/apigw/v4/ApigwOauth2EndpointResourceV4.kt b/src/backend/ci/core/openapi/api-openapi/src/main/kotlin/com/tencent/devops/openapi/api/apigw/v4/ApigwOauth2EndpointResourceV4.kt index dd45b966986..95444b49b17 100644 --- a/src/backend/ci/core/openapi/api-openapi/src/main/kotlin/com/tencent/devops/openapi/api/apigw/v4/ApigwOauth2EndpointResourceV4.kt +++ b/src/backend/ci/core/openapi/api-openapi/src/main/kotlin/com/tencent/devops/openapi/api/apigw/v4/ApigwOauth2EndpointResourceV4.kt @@ -1,7 +1,6 @@ package com.tencent.devops.openapi.api.apigw.v4 import com.tencent.devops.auth.pojo.Oauth2AccessTokenRequest -import com.tencent.devops.auth.pojo.vo.Oauth2AccessTokenVo import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_APP_CODE import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_APP_CODE_DEFAULT_VALUE import com.tencent.devops.common.api.auth.AUTH_HEADER_OAUTH2_CLIENT_ID @@ -44,5 +43,5 @@ interface ApigwOauth2EndpointResourceV4 { clientSecret: String, @ApiParam("oauth2获取token请求报文体", required = true) accessTokenRequest: Oauth2AccessTokenRequest - ): Result + ): Result } diff --git a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwOauth2EndpointResourceV4Impl.kt b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwOauth2EndpointResourceV4Impl.kt index cacfc07715d..49d28aefd80 100644 --- a/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwOauth2EndpointResourceV4Impl.kt +++ b/src/backend/ci/core/openapi/biz-openapi/src/main/kotlin/com/tencent/devops/openapi/resources/apigw/v4/ApigwOauth2EndpointResourceV4Impl.kt @@ -2,7 +2,8 @@ package com.tencent.devops.openapi.resources.apigw.v4 import com.tencent.devops.auth.api.oauth2.Oauth2ServiceEndpointResource import com.tencent.devops.auth.pojo.Oauth2AccessTokenRequest -import com.tencent.devops.auth.pojo.vo.Oauth2AccessTokenVo +import com.tencent.devops.common.api.exception.ErrorCodeException +import com.tencent.devops.common.api.exception.RemoteServiceException import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.common.client.Client import com.tencent.devops.common.web.RestResource @@ -21,16 +22,25 @@ class ApigwOauth2EndpointResourceV4Impl @Autowired constructor( clientId: String, clientSecret: String, accessTokenRequest: Oauth2AccessTokenRequest - ): Result { + ): Result { logger.info("OPENAPI_OAUTH2_ACCESS_TOKEN_V4|$appCode|$clientId") - return client.get(Oauth2ServiceEndpointResource::class).getAccessToken( - clientId = clientId, - clientSecret = clientSecret, - accessTokenRequest = accessTokenRequest - ) + return try { + client.get(Oauth2ServiceEndpointResource::class).getAccessToken( + clientId = clientId, + clientSecret = clientSecret, + accessTokenRequest = accessTokenRequest + ) + } catch (ex: ErrorCodeException) { + Result(status = ex.errorCode.toInt(), message = ex.defaultMessage) + } catch (rex: RemoteServiceException) { + Result(status = rex.errorCode ?: REMOTE_EXCEPTION_CODE, message = rex.errorMessage) + } catch (ignore: Exception) { + throw ignore + } } companion object { val logger = LoggerFactory.getLogger(ApigwOauth2EndpointResourceV4Impl::class.java) + private const val REMOTE_EXCEPTION_CODE = 500 } }