Skip to content

Commit 9e611e5

Browse files
authored
Remove abort() calls and support CONNECTION_URI env (modmail-dev#55)
* Dont use deprecated abort() * Bump version to v1.1.1
1 parent 31a91bb commit 9e611e5

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

app.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
__version__ = "1.1"
1+
__version__ = "1.1.1"
22

33
import os
44

55
from motor.motor_asyncio import AsyncIOMotorClient
66
from sanic import Sanic, response
7-
from sanic.exceptions import abort, NotFound
7+
from sanic.exceptions import NotFound
88
from jinja2 import Environment, FileSystemLoader
99

1010
from core.models import LogEntry
@@ -19,8 +19,11 @@
1919
if prefix == "NONE":
2020
prefix = ""
2121

22-
app = Sanic(__name__)
22+
MONGO_URI = os.getenv("MONGO_URI")
23+
if not MONGO_URI:
24+
MONGO_URI = os.environ['CONNECTION_URI']
2325

26+
app = Sanic(__name__)
2427
app.static("/static", "./static")
2528

2629
jinja_env = Environment(loader=FileSystemLoader("templates"))
@@ -36,7 +39,7 @@ def render_template(name, *args, **kwargs):
3639

3740
@app.listener("before_server_start")
3841
async def init(app, loop):
39-
app.ctx.db = AsyncIOMotorClient(os.getenv("MONGO_URI")).modmail_bot
42+
app.ctx.db = AsyncIOMotorClient(MONGO_URI).modmail_bot
4043

4144

4245
@app.exception(NotFound)
@@ -55,7 +58,7 @@ async def get_raw_logs_file(request, key):
5558
document = await app.ctx.db.logs.find_one({"key": key})
5659

5760
if document is None:
58-
abort(404)
61+
raise NotFound
5962

6063
log_entry = LogEntry(app, document)
6164

@@ -68,7 +71,7 @@ async def get_logs_file(request, key):
6871
document = await app.ctx.db.logs.find_one({"key": key})
6972

7073
if document is None:
71-
abort(404)
74+
raise NotFound
7275

7376
log_entry = LogEntry(app, document)
7477

0 commit comments

Comments
 (0)