private static void addResponseInformation()

in aws-xray-agent/src/main/java/com/amazonaws/xray/agent/runtime/handlers/downstream/HttpClientHandler.java [111:145]


    private static void addResponseInformation(Subsegment subsegment, HttpServiceDownstreamResponseEvent responseEvent) {
        Map<String, Object> responseInformation = new HashMap<>();

        // Add exceptions
        if (responseEvent.getThrown() != null) {
            Throwable exception = responseEvent.getThrown();
            subsegment.addException(exception);
        }

        int responseCode = responseEvent.getStatusCode();
        switch (responseCode/100) {
            case 4:
                subsegment.setError(true);
                if (429 == responseCode) {
                    subsegment.setThrottle(true);
                }
                break;
            case 5:
                subsegment.setFault(true);
                break;
        }
        if (responseCode >= 0) {
            responseInformation.put(STATUS_CODE_KEY, responseCode);
        }

        long contentLength = responseEvent.getContentLength();
        if (contentLength >= 0) {
            // If content length is -1, then the information isn't provided in the web request.
            responseInformation.put(CONTENT_LENGTH_KEY, contentLength);
        }

        if (responseInformation.size() > 0) {
            subsegment.putHttp(HTTP_RESPONSE_KEY, responseInformation);
        }
    }