mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-01 15:53:12 +00:00
Use json_or_text helper for parsing webhook responses
This commit is contained in:
parent
f24f34e3f1
commit
f82ec46acf
@ -26,7 +26,6 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from urllib.parse import quote as urlquote
|
from urllib.parse import quote as urlquote
|
||||||
@ -44,7 +43,7 @@ from ..user import BaseUser, User
|
|||||||
from ..flags import MessageFlags
|
from ..flags import MessageFlags
|
||||||
from ..asset import Asset
|
from ..asset import Asset
|
||||||
from ..partial_emoji import PartialEmoji
|
from ..partial_emoji import PartialEmoji
|
||||||
from ..http import Route, handle_message_parameters, MultipartParameters, HTTPClient
|
from ..http import Route, handle_message_parameters, MultipartParameters, HTTPClient, json_or_text
|
||||||
from ..mixins import Hashable
|
from ..mixins import Hashable
|
||||||
from ..channel import TextChannel, PartialMessageable
|
from ..channel import TextChannel, PartialMessageable
|
||||||
from ..file import File
|
from ..file import File
|
||||||
@ -182,9 +181,7 @@ class AsyncWebhookAdapter:
|
|||||||
url,
|
url,
|
||||||
response.status,
|
response.status,
|
||||||
)
|
)
|
||||||
data = (await response.text(encoding='utf-8')) or None
|
data = await json_or_text(response)
|
||||||
if data and response.headers['Content-Type'] == 'application/json':
|
|
||||||
data = json.loads(data)
|
|
||||||
|
|
||||||
remaining = response.headers.get('X-Ratelimit-Remaining')
|
remaining = response.headers.get('X-Ratelimit-Remaining')
|
||||||
if remaining == '0' and response.status != 429:
|
if remaining == '0' and response.status != 429:
|
||||||
|
@ -178,8 +178,11 @@ class WebhookAdapter:
|
|||||||
response.status = response.status_code # type: ignore
|
response.status = response.status_code # type: ignore
|
||||||
|
|
||||||
data = response.text or None
|
data = response.text or None
|
||||||
if data and response.headers['Content-Type'] == 'application/json':
|
try:
|
||||||
data = json.loads(data)
|
if data and response.headers['Content-Type'] == 'application/json':
|
||||||
|
data = json.loads(data)
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
remaining = response.headers.get('X-Ratelimit-Remaining')
|
remaining = response.headers.get('X-Ratelimit-Remaining')
|
||||||
if remaining == '0' and response.status_code != 429:
|
if remaining == '0' and response.status_code != 429:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user