public void afterError()

in aws-xray-recorder-sdk-aws-sdk/src/main/java/com/amazonaws/xray/handlers/TracingHandler.java [399:449]


    public void afterError(Request<?> request, Response<?> response, Exception e) {
        if (isSubsegmentDuplicate(recorder.getCurrentSubsegmentOptional(), request)) {
            Optional<Subsegment> currentSubsegmentOptional = recorder.getCurrentSubsegmentOptional();
            if (!currentSubsegmentOptional.isPresent()) {
                return;
            }
            Subsegment currentSubsegment = currentSubsegmentOptional.get();

            int statusCode = -1;

            if (null != response) {
                statusCode = response.getHttpResponse().getStatusCode();
            } else {
                if (e instanceof AmazonServiceException) {
                    AmazonServiceException ase = (AmazonServiceException) e;
                    statusCode = ase.getStatusCode();
                    // The S3 client will throw and re-swallow AmazonServiceExceptions if they have these status codes. Customers
                    // will never see the exceptions in their application code but they still travel through our
                    // TracingHandler#afterError method. We special case these status codes in order to prevent addition of the
                    // full exception object to the current subsegment. Instead, we'll just add any exception error message to the
                    // current subsegment's cause's message.
                    if ((304 == statusCode || 412 == statusCode) && S3_SERVICE_NAME.equals(ase.getServiceName())) {
                        populateAndEndSubsegment(currentSubsegment, request, response, ase);
                        return;
                    }
                    if (RetryUtils.isThrottlingException(ase)) {
                        currentSubsegment.setError(true);
                        currentSubsegment.setThrottle(true);
                    }
                }
            }

            if (-1 != statusCode) {
                int statusCodePrefix = statusCode / 100;
                if (4 == statusCodePrefix) {
                    currentSubsegment.setError(true);
                    if (429 == statusCode) {
                        currentSubsegment.setThrottle(true);
                    }
                }
            }

            currentSubsegment.addException(e);

            if (e instanceof AmazonServiceException) {
                populateAndEndSubsegment(currentSubsegment, request, response, (AmazonServiceException) e);
            } else {
                populateAndEndSubsegment(currentSubsegment, request, response);
            }
        }
    }