Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TelegramBot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
TelegramBot
Commits
d73fe239
Commit
d73fe239
authored
Jun 20, 2018
by
Jack'lul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Throw InvalidBotTokenException when token is rejected by Telegram API
parent
5676b756
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
1 deletion
+33
-1
InvalidBotTokenException.php
src/Exception/InvalidBotTokenException.php
+25
-0
Request.php
src/Request.php
+8
-1
No files found.
src/Exception/InvalidBotTokenException.php
0 → 100644
View file @
d73fe239
<?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!"
);
}
}
src/Request.php
View file @
d73fe239
...
...
@@ -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
;
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment