gameTransportFailureCode function
Maps a transport failure to timeout or network, walking the cause
chain. Shared by the skin http bridge and the rewards fetch. Port of
Android failureCodeOf (iOS GameTransport.timeoutCode).
Implementation
String gameTransportFailureCode(Object error) {
Object? cause = error;
var depth = 0;
while (cause != null && depth < 8) {
if (cause is TimeoutException) return GameBridgeError.timeout;
if (cause is SocketException &&
cause.message.toLowerCase().contains('timeout')) {
return GameBridgeError.timeout;
}
if (cause is HttpException &&
cause.message.toLowerCase().contains('timeout')) {
return GameBridgeError.timeout;
}
if (cause is NetworkException) {
if (cause.kind.toLowerCase().contains('timeout')) {
return GameBridgeError.timeout;
}
cause = cause.cause;
} else {
cause = null;
}
depth++;
}
final text = error.toString().toLowerCase();
if (text.contains('timed out') || text.contains('timeout')) {
_log.d('Game transport failure matched by message ($error)');
return GameBridgeError.timeout;
}
return GameBridgeError.network;
}