serve: Improve error handling on /get_license_challenge

This commit is contained in:
rlaphoenix 2022-08-06 09:21:06 +01:00
parent f2ed83205b
commit 11a2358002
1 changed files with 12 additions and 1 deletions

View File

@ -20,7 +20,8 @@ except ImportError:
from pywidevine import __version__ from pywidevine import __version__
from pywidevine.cdm import Cdm from pywidevine.cdm import Cdm
from pywidevine.device import Device from pywidevine.device import Device
from pywidevine.exceptions import TooManySessions, InvalidSession, SignatureMismatch from pywidevine.exceptions import TooManySessions, InvalidSession, SignatureMismatch, InvalidInitData, \
InvalidLicenseType
from pywidevine.license_protocol_pb2 import License from pywidevine.license_protocol_pb2 import License
routes = web.RouteTableDef() routes = web.RouteTableDef()
@ -225,6 +226,16 @@ async def get_license_challenge(request: web.Request) -> web.Response:
"status": 400, "status": 400,
"message": f"Invalid Session ID '{session_id.hex()}', it may have expired." "message": f"Invalid Session ID '{session_id.hex()}', it may have expired."
}, status=400) }, status=400)
except InvalidInitData as e:
return web.json_response({
"status": 400,
"message": f"Invalid Init Data, {e}"
}, status=400)
except InvalidLicenseType:
return web.json_response({
"status": 400,
"message": f"Invalid License Type '{license_type}'"
}, status=400)
return web.json_response({ return web.json_response({
"status": 200, "status": 200,