in agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/telemetry/TelemetryChannel.java [284:343]
private Consumer<HttpResponse> responseHandler(
String instrumentationKey,
long startTime,
Runnable onSuccess,
Consumer<Boolean> onFailure,
OperationLogger operationLogger) {
return response ->
response
.getBodyAsString()
.switchIfEmpty(Mono.just(""))
.subscribe(
body -> {
int statusCode = response.getStatusCode();
switch (statusCode) {
case 200: // SUCCESS
operationLogger.recordSuccess();
onSuccess.run();
break;
case 206: // PARTIAL CONTENT, Breeze-specific: PARTIAL SUCCESS
operationLogger.recordFailure(
getErrorMessageFromPartialSuccessResponse(body));
onFailure.accept(false);
break;
case 401: // breeze returns if aad enabled and no authentication token provided
case 403: // breeze returns if aad enabled or disabled (both cases) and
// wrong/expired credentials provided
operationLogger.recordFailure(
getErrorMessageFromCredentialRelatedResponse(statusCode, body));
onFailure.accept(true);
break;
case 408: // REQUEST TIMEOUT
case 429: // TOO MANY REQUESTS
case 500: // INTERNAL SERVER ERROR
case 503: // SERVICE UNAVAILABLE
operationLogger.recordFailure(
"received response code "
+ statusCode
+ " (telemetry will be stored to disk and retried later)");
onFailure.accept(true);
break;
case 439: // Breeze-specific: THROTTLED OVER EXTENDED TIME
// TODO handle throttling
operationLogger.recordFailure(
"received response code 439 (throttled over extended time)");
onFailure.accept(false);
break;
default:
operationLogger.recordFailure("received response code: " + statusCode);
onFailure.accept(false);
}
if (!isStatsbeat) {
handleStatsbeatOnResponse(instrumentationKey, startTime, statusCode);
}
},
exception -> {
operationLogger.recordFailure("exception retrieving response body", exception);
onFailure.accept(false);
});
}