Skip to content

Commit

Permalink
Merge pull request #4291 from mingshewhe/feature_4284
Browse files Browse the repository at this point in the history
feature: git获取文件内容超过1M应返回指定的错误码 #4284
  • Loading branch information
irwinsun authored Jun 16, 2021
2 parents 4eff940 + 731e0de commit 2695ec0
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ package com.tencent.devops.common.client
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import com.tencent.devops.common.api.exception.ClientException
import com.tencent.devops.common.api.exception.OperationException
import com.tencent.devops.common.api.exception.RemoteServiceException
import com.tencent.devops.common.api.exception.ErrorCodeException
import com.tencent.devops.common.api.pojo.Result
import feign.Response
import feign.codec.ErrorDecoder
Expand All @@ -45,18 +44,20 @@ import java.io.IOException
*/
@Service
class ClientErrorDecoder @Autowired constructor(val objectMapper: ObjectMapper) : ErrorDecoder {

override fun decode(methodKey: String, response: Response): Exception {
// 首先判断返回结果是否能被序列化
val responseStream = response.body().asInputStream()
val result: Result<*>
try {
result = objectMapper.readValue(responseStream)
} catch (e: IOException) {
} catch (ignore: IOException) {
return ClientException("内部服务返回结果无法解析")
}
if (response.status() == OperationException.statusCode) {
throw OperationException(result.message ?: "")
}
return RemoteServiceException(result.message ?: "", response.status())
return ErrorCodeException(
statusCode = response.status(),
errorCode = result.status.toString(),
defaultMessage = result.message
)
}
}

0 comments on commit 2695ec0

Please sign in to comment.