Commit d73fe239 authored by Jack'lul's avatar Jack'lul

Throw InvalidBotTokenException when token is rejected by Telegram API

parent 5676b756
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Exception;
/**
* Thrown when bot token is invalid
*/
class InvalidBotTokenException extends TelegramException
{
/**
* InvalidBotTokenException constructor
*/
public function __construct()
{
parent::__construct("Invalid bot token!");
}
}
......@@ -14,6 +14,7 @@ use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use Longman\TelegramBot\Entities\File;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Exception\InvalidBotTokenException;
use Longman\TelegramBot\Exception\TelegramException;
/**
......@@ -463,7 +464,13 @@ class Request
throw new TelegramException('Telegram returned an invalid response! Please review your bot name and API key.');
}
return new ServerResponse($response, $bot_username);
$response = new ServerResponse($response, $bot_username);
if (!$response->isOk() && $response->getErrorCode() === 401 && $response->getDescription() === 'Unauthorized') {
throw new InvalidBotTokenException();
}
return $response;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment