Overview
Proper error handling is crucial for building reliable Telegram bots and clients. Gogram provides comprehensive error handling mechanisms.Error Categories
Telegram API errors are categorized by HTTP-like status codes:303 - SeeOther
Redirect to another data center or endpoint
400 - BadRequest
Invalid request parameters or malformed data
401 - Unauthorized
Authentication required or session expired
403 - Forbidden
Access denied or insufficient permissions
406 - NotAcceptable
Request not acceptable (e.g., duplicate message)
420 - Flood
Too many requests, rate limiting active
500 - InternalServerError
Telegram server error, retry later
Common Error Examples
- 400 - BadRequest
- 403 - Forbidden
- 420 - Flood
- 500 - Internal
Error Types
Connection Errors
Handling API Errors
Every API call returns two values: the result and an error. Always check the error before using the result.Error Handler
The client config asks for a global error handler function that gets called for unhandled errors in event handlers.Handling Flood Waits
Some API calls may return aFLOOD_WAIT error if you exceed rate limits. Implement retry logic with exponential backoff.
The client config also allows setting a custom flood wait handler.
Best Practices
Always Check Errors
Never ignore errors - always check and handle them
Use Global Error Handler
Implement a global error handler for unhandled errors