public void modifyResponse()

in alibabacloud-gateway-sls/java/src/main/java/com/aliyun/gateway/sls/Client.java [199:244]


    public void modifyResponse(com.aliyun.gateway.spi.models.InterceptorContext context, com.aliyun.gateway.spi.models.AttributeMap attributeMap) throws Exception {
        com.aliyun.gateway.spi.models.InterceptorContext.InterceptorContextRequest request = context.request;
        com.aliyun.gateway.spi.models.InterceptorContext.InterceptorContextResponse response = context.response;
        if (com.aliyun.teautil.Common.is4xx(response.statusCode) || com.aliyun.teautil.Common.is5xx(response.statusCode)) {
            Object error = com.aliyun.teautil.Common.readAsJSON(response.body);
            java.util.Map<String, Object> resMap = com.aliyun.teautil.Common.assertAsMap(error);
            throw new TeaException(TeaConverter.buildMap(
                new TeaPair("code", resMap.get("errorCode")),
                new TeaPair("message", resMap.get("errorMessage")),
                new TeaPair("accessDeniedDetail", resMap.get("accessDeniedDetail")),
                new TeaPair("data", TeaConverter.buildMap(
                    new TeaPair("httpCode", response.statusCode),
                    new TeaPair("requestId", response.headers.get("x-log-requestid")),
                    new TeaPair("statusCode", response.statusCode)
                ))
            ));
        }

        if (!com.aliyun.teautil.Common.isUnset(response.body)) {
            String bodyrawSize = response.headers.get("x-log-bodyrawsize");
            String compressType = response.headers.get("x-log-compresstype");
            java.io.InputStream uncompressedData = response.body;
            if (!com.aliyun.teautil.Common.isUnset(bodyrawSize) && !com.aliyun.teautil.Common.isUnset(compressType)) {
                uncompressedData = com.aliyun.gateway.sls.util.Client.readAndUncompressBlock(response.body, compressType, bodyrawSize);
            }

            if (com.aliyun.teautil.Common.equalString(request.bodyType, "binary")) {
                response.deserializedBody = uncompressedData;
            } else if (com.aliyun.teautil.Common.equalString(request.bodyType, "byte")) {
                byte[] byt = com.aliyun.teautil.Common.readAsBytes(uncompressedData);
                response.deserializedBody = byt;
            } else if (com.aliyun.teautil.Common.equalString(request.bodyType, "string")) {
                response.deserializedBody = com.aliyun.teautil.Common.readAsString(uncompressedData);
            } else if (com.aliyun.teautil.Common.equalString(request.bodyType, "json")) {
                Object obj = com.aliyun.teautil.Common.readAsJSON(uncompressedData);
                // var res = Util.assertAsMap(obj);
                response.deserializedBody = obj;
            } else if (com.aliyun.teautil.Common.equalString(request.bodyType, "array")) {
                response.deserializedBody = com.aliyun.teautil.Common.readAsJSON(uncompressedData);
            } else {
                response.deserializedBody = com.aliyun.teautil.Common.readAsString(uncompressedData);
            }

        }

    }