better timeout handling #14
@ -159,7 +159,7 @@ async def generate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
start_time = time.monotonic()
|
start_time = time.monotonic()
|
||||||
|
try:
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.post(
|
async with session.post(
|
||||||
"https://image.novelai.net/ai/generate-image",
|
"https://image.novelai.net/ai/generate-image",
|
||||||
@ -169,6 +169,10 @@ async def generate(
|
|||||||
) as response:
|
) as response:
|
||||||
response_bytes = await response.read()
|
response_bytes = await response.read()
|
||||||
status_code = response.status
|
status_code = response.status
|
||||||
|
except aiohttp.TimeoutError:
|
||||||
|
await interaction.followup.send("Error: the request timed out.")
|
||||||
|
except aiohttp.ClientError as e:
|
||||||
|
await interaction.followup.send(f"Error: {e}")
|
||||||
|
|
||||||
duration = time.monotonic() - start_time
|
duration = time.monotonic() - start_time
|
||||||
logger.info("Image creation took %.2f seconds", duration)
|
logger.info("Image creation took %.2f seconds", duration)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user