handleUndecodable method
Called for an incoming data frame this session could not read.
Covers a frame no codec claimed and one that threw on the way in. The default reports a SessionEventType.error event and answers the peer with Protocol.errorInvalidMessage: a client that hears nothing back cannot tell a rejected frame from a slow one, and waits for a reply that is never coming. Sessions may override it to say something more precise first (a relay session diagnoses a CRDT-aware sync client that connected to the wrong server).
Implementation
@protected
void handleUndecodable(List<int> data) {
addSessionEvent(
SessionEventGeneric(
sessionId: id,
type: SessionEventType.error,
message: 'Failed to decode message: $data. '
'This message is not supported by any plugin.',
),
);
// Only for a frame that belongs to the protocol. A plugin frame this build
// cannot read means the peer has a plugin this one does not — a difference
// in configuration, and answering it would turn every frame of a working
// connection into an error the peer displays.
final type = Message.getTypeOrNull(data);
if (type != null && type >= MessageTypeValue.firstPluginValue) {
return;
}
unawaited(
sendMessage(
Message.error(
// Names no document, because this answer is not about one: the frame
// it answers did not decode, and it is the frame that would have
// said which. A client takes an error that names none.
documentId: '',
code: Protocol.errorInvalidMessage,
message: 'This frame could not be read.',
),
),
);
}