Skip to content

Commit

Permalink
First steps for move from aiohttp to httpx
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5c authored and classabbyamp committed Jan 13, 2023
1 parent 9368ccd commit a4c8a05
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 9 additions & 4 deletions common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from typing import Union

import aiohttp
import httpx

import discord
import discord.ext.commands as commands
Expand Down Expand Up @@ -125,12 +126,16 @@ def __str__(self):

class BotHTTPError(Exception):
"""Raised whan a requests fails (status != 200) in a command."""
def __init__(self, response: aiohttp.ClientResponse):
msg = f"Request failed: {response.status} {response.reason}"
def __init__(self, response: aiohttp.ClientResponse | httpx.Response):
if isinstance(response, aiohttp.ClientResponse):
self.status = response.status
self.reason = response.reason
else:
self.status = response.status_code
self.reason = response.reason_phrase
msg = f"Request failed: {self.status} {self.reason}"
super().__init__(msg)
self.response = response
self.status = response.status
self.reason = response.reason


# --- Converters ---
Expand Down
3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from types import SimpleNamespace
from pathlib import Path

import httpx
import pytz

import discord
Expand Down Expand Up @@ -69,6 +70,8 @@
# Let's store stuff here.
bot.qrm.connector = connector
bot.qrm.debug_mode = debug_mode
# TODO: Add code to close the client
bot.qrm.httpx_client = httpx.AsyncClient()


# --- Commands ---
Expand Down

0 comments on commit a4c8a05

Please sign in to comment.