mirror of
https://github.com/yawaflua/Flask-Discord.git
synced 2025-12-10 12:29:30 +02:00
Handle JSON decode error
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
class HttpException(Exception):
|
class HttpException(Exception):
|
||||||
"""Base Exception class representing a HTTP exception."""
|
"""Base Exception class representing a HTTP exception."""
|
||||||
|
|
||||||
@@ -24,11 +27,16 @@ class RateLimited(HttpException):
|
|||||||
|
|
||||||
def __init__(self, response):
|
def __init__(self, response):
|
||||||
self.response = response
|
self.response = response
|
||||||
self.json = self.response.json()
|
try:
|
||||||
self.message = self.json["message"]
|
self.json = self.response.json()
|
||||||
self.is_global = self.json["global"]
|
except json.JSONDecodeError:
|
||||||
self.retry_after = self.json["retry_after"]
|
self.json = dict()
|
||||||
super().__init__(self.json["message"])
|
self.message = self.response.text
|
||||||
|
else:
|
||||||
|
self.message = self.json["message"]
|
||||||
|
self.is_global = self.json["global"]
|
||||||
|
self.retry_after = self.json["retry_after"]
|
||||||
|
super().__init__(self.message)
|
||||||
|
|
||||||
|
|
||||||
class Unauthorized(HttpException):
|
class Unauthorized(HttpException):
|
||||||
|
|||||||
Reference in New Issue
Block a user