-
Notifications
You must be signed in to change notification settings - Fork 1
Error Handling
All method invocations (using either the Bot or Client APIs) should be expected to occasionally fail (if for no other reason than transient network conditions).
Telefrag will throw a TelegramException
whenever it fails to invoke a Telegram method successfully. The properties on this exception can be used to determine what went wrong:
-
Activity - References the
MethodActivity
that describes what Telegram method Telefrag was trying to call -
Context - The
Context
that encountered the error -
HttpErrorCode - The HTTP status code returned from the server. If this is
0
, the error was at the network layer and no HTTP response was received. - HttpErrorDescription - The HTTP status description returned from the server
-
TelegramErrorCode - The error code reported by Telegram in its JSON error response. If this is
0
, that means the error was at the network or HTTP layer and was not an Error object communicated by Telegram. -
TelegramErrorDescription - The error description provided by the Telegram server. If this is
null
, the error was at the network or HTTP layer and was not an Error object communicated by Telegram.
The Message property will describe whether the issue was a network, HTTP, or Telegram-level error.
Most functions will throw a ArgumentNullException or InvalidOperationException if called with bad arguments.
Other exceptions to be aware of:
- ComponentConflictException - You are registering a component that conflicts with one marked durable.
- NoLocalIpException - Telefrag couldn't determine your machine's local IP address (and it needed it for something)
- CertificateNotFoundException - You told Telefrag to use a certificate it couldn't find the cert store.
- LayerException - You tried to add a layer that exists or move a layer that doesn't.
-
EventException - You made an
Event
with an inaccessible setter. - ConstructionException - DI construction of an object instance failed
- NoSecurityProviderException - A bot didn't have a SecurityProvider registered and an operation required one.
-
RequiredComponentMissingException - You tried to
Resolve()
a component that doesn't exist and you said it wasrequired
. - TextException - You tried to do something clever with text that Telegram doesn't allow, such as an unsupported HTML tag or non-matching brackets/tags.
-
WebhooksNotConfiguredException - You tried to
SetWebhook()
without having webhooks tied into the ASP (or other) pipeline - WebhookSetupException - We failed to map webhooks into the endpoint routing for ASP.NET
Telefrag typically allows exceptions in user (your) code to propagate back to you as you would expect; the one exception (no pun intended) would be unhandled exceptions in event handlers.
Telefrag allows the raiser of the event to specify whether they would like unhandled exceptions encountered in event handlers to propagate back to them or not. In most built-in scenarios this is not the case, and unhandled exceptions in event handlers will simply be logged as an error (using Context.Logger
) and ignored.
When using the Bot Toolkit, you can control how unhandled exceptions in constructs like commands and callbacks are handled by changing the value of Toolkit.Settings.UserErrorHandling
.
- Reply - Reply to the Telegram user with the exception message and stack trace (probably only use this in non-production)
- Ignore - Do nothing
- ReplyAndLog - Log the exception and reply to the user
- IgnoreAndLog - Log the exception only