in facebook-core/src/main/java/com/facebook/appevents/AppEventQueue.kt [219:273]
fun handleResponse(
accessTokenAppId: AccessTokenAppIdPair,
request: GraphRequest,
response: GraphResponse,
appEvents: SessionEventsState,
flushState: FlushStatistics
) {
val error = response.error
var resultDescription = "Success"
var flushResult = FlushResult.SUCCESS
if (error != null) {
if (error.errorCode == NO_CONNECTIVITY_ERROR_CODE) {
resultDescription = "Failed: No Connectivity"
flushResult = FlushResult.NO_CONNECTIVITY
} else {
resultDescription =
String.format(
"Failed:\n Response: %s\n Error %s", response.toString(), error.toString())
flushResult = FlushResult.SERVER_ERROR
}
}
if (FacebookSdk.isLoggingBehaviorEnabled(LoggingBehavior.APP_EVENTS)) {
val eventsJsonString = request.tag as String?
val prettyPrintedEvents: String
prettyPrintedEvents =
try {
val jsonArray = JSONArray(eventsJsonString)
jsonArray.toString(2)
} catch (exc: JSONException) {
"<Can't encode events for debug logging>"
}
log(
LoggingBehavior.APP_EVENTS,
TAG,
"Flush completed\nParams: %s\n Result: %s\n Events JSON: %s",
request.graphObject.toString(),
resultDescription,
prettyPrintedEvents)
}
appEvents.clearInFlightAndStats(error != null)
if (flushResult === FlushResult.NO_CONNECTIVITY) {
// We may call this for multiple requests in a batch, which is slightly inefficient
// since in principle we could call it once for all failed requests, but the impact is
// likely to be minimal. We don't call this for other server errors, because if an event
// failed because it was malformed, etc., continually retrying it will cause subsequent
// events to not be logged either.
FacebookSdk.getExecutor().execute { persistEvents(accessTokenAppId, appEvents) }
}
if (flushResult !== FlushResult.SUCCESS) {
// We assume that connectivity issues are more significant to report than server issues.
if (flushState.result !== FlushResult.NO_CONNECTIVITY) {
flushState.result = flushResult
}
}
}