botman / driver-telegram

BotMan Telegram Driver
MIT License
88 stars 75 forks source link

Optionally throw exception when http call fails. #73

Closed sh41 closed 4 years ago

sh41 commented 4 years ago

Add configuration option/feature flag named throw_http_exceptions to ensure that there are no BC breaks.

Enable in config array:

'telegram' => [
    'token' => 'YOUR-TELEGRAM-TOKEN-HERE',
        'throw_http_exceptions' => true,
]

When set to true this will perform various checks on the response from an http call and throw a TelegramConnectionException if there are any problems. The message content will contain debugging information. The telegram token will be removed from the message so as not to leak credentials.

Have added new tests for this.

Also fixed it_throws_exception_in_get_user test as it would not have correctly picked up situation where no exception was thrown.

codecov[bot] commented 4 years ago

Codecov Report

Merging #73 into master will increase coverage by 1.41%. The diff coverage is 89.23%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #73      +/-   ##
============================================
+ Coverage     76.20%   77.62%   +1.41%     
- Complexity      117      133      +16     
============================================
  Files            11       11              
  Lines           374      429      +55     
============================================
+ Hits            285      333      +48     
- Misses           89       96       +7     
Impacted Files Coverage Δ Complexity Δ
src/Providers/TelegramServiceProvider.php 0.00% <0.00%> (ø) 4.00 <0.00> (ø)
src/TelegramDriver.php 92.23% <90.62%> (-1.19%) 60.00 <9.00> (+16.00) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 5ced159...72971b5. Read the comment docs.

sh41 commented 4 years ago

After using this for a while I've added a configuration option to allow retrying of server errors. I found that occasionally Telegram will return a 500 status code, or if you send too many messages too quickly a 429 with a retry message. Configuring with this will enable retrying (if throw_http_exceptions is enabled).

'telegram' => [
    'token' => 'YOUR-TELEGRAM-TOKEN-HERE',
        'throw_http_exceptions' => true,
        'retry_http_exceptions' => 5,
        'retry_http_exceptions_multiplier' => 2,
]
feralheart commented 4 years ago

Hi @sh41 , Thank you for your contribution.