Add try except when closing program

This commit is contained in:
2022-12-06 12:37:20 +01:00
parent f4fe22fd5e
commit a9a6884d39
2 changed files with 9 additions and 3 deletions

View File

@ -165,7 +165,7 @@ def send_to_discord(feed=None) -> None:
raise
try:
webhook_url: str = str(reader.get_tag(entry.feed.url, "webhook"))
webhook_url: str = str(reader.get_tag(entry.feed_url, "webhook"))
except TagNotFoundError:
logger.error("Tag not found", exc_info=True)
raise

View File

@ -37,7 +37,7 @@ from fastapi import FastAPI, Form, HTTPException, Request
from fastapi.responses import FileResponse, HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from reader import EntryCounts, Feed, FeedCounts, ResourceNotFoundError
from reader import EntryCounts, Feed, FeedCounts, ReaderError, ResourceNotFoundError
from starlette.templating import _TemplateResponse
from tomlkit.toml_document import TOMLDocument
@ -254,8 +254,14 @@ def shutdown() -> None:
It stops the scheduler."""
scheduler: BackgroundScheduler = BackgroundScheduler()
scheduler.shutdown()
logger.info("Scheduler stopped.")
reader.close()
try:
reader.close()
except ReaderError:
logger.error("Error closing reader.", exc_info=True)
sys.exit()
logger.info("Reader closed.")
if __name__ == "__main__":