Prepare monorepo
This commit is contained in:
parent
a1ddb43ed0
commit
938582155d
61 changed files with 5 additions and 5 deletions
0
backend/app/util/__init__.py
Normal file
0
backend/app/util/__init__.py
Normal file
14
backend/app/util/errors.py
Normal file
14
backend/app/util/errors.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
class NotFoundError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class InvalidStateError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class InsufficientPermissionsError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class InvalidTokenAudienceError(Exception):
|
||||
pass
|
25
backend/app/util/websocket_wrapper.py
Normal file
25
backend/app/util/websocket_wrapper.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
import logging
|
||||
from fastapi import WebSocket, WebSocketDisconnect
|
||||
from websockets import ConnectionClosed
|
||||
|
||||
logger = logging.getLogger("gunicorn.error")
|
||||
|
||||
# Wrapper to transform a FastAPI websocket to a standard websocket
|
||||
class WebSocketWrapper():
|
||||
def __init__(self, websocket: WebSocket):
|
||||
self._websocket = websocket
|
||||
|
||||
async def recv(self) -> str:
|
||||
try:
|
||||
text = await self._websocket.receive_text()
|
||||
logger.info("Message received: %s", text)
|
||||
return text
|
||||
except WebSocketDisconnect as e:
|
||||
raise ConnectionClosed(e.code, 'WebSocketWrapper')
|
||||
|
||||
async def send(self, msg: str) -> None:
|
||||
logger.info("Message sent: %s", msg)
|
||||
await self._websocket.send_text(msg)
|
||||
|
||||
async def close(self, code: int, reason: str) -> None:
|
||||
await self._websocket.close(code)
|
Loading…
Add table
Add a link
Reference in a new issue