Source code for luna_backport3.app.handlers.liveness_handler

from luna3.common.luna_response import LunaResponse
from sanic.response import HTTPResponse

from app.handlers.base_handler import APIProxyBaseHandler
from crutches_on_wheels.cow.errors.errors import ErrorInfo
from crutches_on_wheels.cow.errors.exception import VLException


[docs]class LivenessHandler(APIProxyBaseHandler): """ Handler for liveness prediction service """ allowedMethods = ("POST",)
[docs] async def postProcessingPost(self, response: LunaResponse) -> HTTPResponse: """ Default post processing response from the service Args: response: response Returns: response in api format """ responseJson = response.json for imageDict in responseJson["images"]: if (error := imageDict.get("error")) is not None: imageDict["error"] = {"error_code": error["error_code"], "detail": error["detail"]} return self.success(response.statusCode, outputJson=responseJson, extraHeaders=response.headers)
[docs] async def postProcessingFailedRequest(self, response: LunaResponse) -> HTTPResponse: """ Post processing failed response from the service Args: response: response Returns: response in api format """ raise VLException(ErrorInfo.fromDict(response.json), response.statusCode, False)