ptgc
MTProto client for Dart

Exceptions

Part of the API Reference. See Error Handling for a guide to catching these in practice.

PtgcException

The base type every exception ptgc throws extends. Catch this for blanket handling of anything the package itself raises (as opposed to, say, a FormatException from your own code).

sealed class PtgcException implements Exception {
  String get message;
}

RpcException

Telegram rejected a request with an error ptgc doesn’t have a more specific type for — the general-purpose case.

class RpcException extends PtgcException {
  final int code;
  final String description;
}

code/description mirror Telegram’s raw error_code/error_message (e.g. 400/'CHAT_ADMIN_REQUIRED') — match on description for specific known errors. See Handling RPC Errors.

FloodWaitException

You’re being rate-limited.

class FloodWaitException extends PtgcException {
  final Duration duration;
}

Wait at least duration before retrying the same call. See Handling Flood Waits.

AuthRequiredException

A method that needs a signed-in session was called before login completed, or the session expired/was revoked server-side (e.g. logged out remotely, or the account was deactivated). See Handling an Expired Session.

TwoFactorRequiredException

auth.checkPassword was called without a pending password challenge from auth.signIn — i.e. signIn never returned SignInStatus.passwordRequired in the first place.

PeerNotFoundException

A username, phone number, or ID couldn’t be resolved to a cached peer — see Peer Cache for why, and Handling “Peer Not Found” for the fix.

class PeerNotFoundException extends PtgcException {
  final String peer;
}