Skip to content

Commit

Permalink
Handle invalid configuration in stream endpoints and show instruction…
Browse files Browse the repository at this point in the history
… stream
  • Loading branch information
mhdzumair committed Jan 18, 2025
1 parent 364e840 commit 9c2258a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions api/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from utils import const
from utils.crypto import crypto_utils
from utils.network import get_client_ip
from utils.parser import create_exception_stream


async def find_route_handler(app, request: Request) -> Optional[Callable]:
Expand Down Expand Up @@ -68,14 +69,22 @@ async def dispatch(self, request: Request, call_next: Callable):
# Decrypt and parse the UserData from secret_str
try:
user_data = await crypto_utils.decrypt_user_data(secret_str)
except ValidationError as error:
return JSONResponse(
{
"status": "error",
"message": error.errors()[0]["msg"],
}
)
except ValueError:
except (ValueError, ValidationError):
# check if the endpoint is for /streams
if endpoint and endpoint.__name__ == "get_streams":
return JSONResponse(
{
"streams": [
create_exception_stream(
settings.addon_name,
"Invalid MediaFusion configuration.\nDelete the Invalid MediaFusion installed addon and reconfigure it.",
"invalid_config.mp4",
).model_dump(exclude_none=True, by_alias=True)
]
},
headers=const.CORS_HEADERS,
)

return JSONResponse(
{
"status": "error",
Expand Down
Binary file added resources/exceptions/invalid_config.mp4
Binary file not shown.

0 comments on commit 9c2258a

Please sign in to comment.