Skip to content

Commit

Permalink
feature: git获取文件内容超过1M应返回指定的错误码 TencentBlueKing#4284
Browse files Browse the repository at this point in the history
  • Loading branch information
mingshewhe committed Jun 16, 2021
1 parent 3077bd8 commit 731e0de
Showing 1 changed file with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ 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.ErrorCodeException
import com.tencent.devops.common.api.exception.OperationException
import com.tencent.devops.common.api.exception.RemoteServiceException
import com.tencent.devops.common.api.pojo.Result
import feign.Response
import feign.codec.ErrorDecoder
Expand All @@ -46,23 +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 (result.status == OperationException.statusCode) {
throw OperationException(result.message ?: "")
} else if (response.status() == OperationException.statusCode) {
throw ErrorCodeException(
errorCode = result.status.toString(),
defaultMessage = result.message
)
}
return RemoteServiceException(result.message ?: "", response.status())
return ErrorCodeException(
statusCode = response.status(),
errorCode = result.status.toString(),
defaultMessage = result.message
)
}
}

0 comments on commit 731e0de

Please sign in to comment.