4343 from urllib2 import HTTPError
4444
4545from telegram import (InputFile , TelegramError )
46+ from telegram .error import Unauthorized , NetworkError , TimedOut
4647
4748
4849def _parse (json_data ):
@@ -79,7 +80,7 @@ def decorator(*args, **kwargs):
7980 # `HTTPError` inherits from `URLError` so `HTTPError` handling must
8081 # come first.
8182 if error .getcode () == 403 :
82- raise TelegramError ( ' Unauthorized' )
83+ raise Unauthorized ( )
8384 if error .getcode () == 502 :
8485 raise TelegramError ('Bad Gateway' )
8586
@@ -88,19 +89,20 @@ def decorator(*args, **kwargs):
8889 except ValueError :
8990 message = 'Unknown HTTPError {0}' .format (error .getcode ())
9091
91- raise TelegramError (message )
92+ raise NetworkError (message )
9293
9394 except URLError as error :
94- raise TelegramError ('URLError: {0!r}' .format (error ))
95+ raise NetworkError ('URLError: {0!r}' .format (error ))
9596
9697 except (SSLError , socket .timeout ) as error :
97- if "operation timed out" in str (error ):
98- raise TelegramError ("Timed out" )
98+ err_s = str (error )
99+ if "operation timed out" in err_s :
100+ raise TimedOut ()
99101
100- raise TelegramError ( str ( error ) )
102+ raise NetworkError ( err_s )
101103
102104 except HTTPException as error :
103- raise TelegramError ('HTTPException: {0!r}' .format (error ))
105+ raise NetworkError ('HTTPException: {0!r}' .format (error ))
104106
105107 return decorator
106108
0 commit comments