Exemplo n.º 1
0
async def error_middleware(request: web.Request,
                           handler: Callable) -> web.Response:
    """Middleware for handling server exceptions."""
    try:
        return await handler(request)
    except Exception as exc:
        server_logger.exception(
            "caught exception while handing over to endpoint")
        return web.json_response({"error": str(exc)}, status=500)
Exemplo n.º 2
0
def read_gpio_by_shadow(shadow_name: str) -> int:
    try:
        gpio = libgpio.GPIO(shadow=shadow_name)
        val = gpio.get_value()
        gpio.close()
        return int(val)
    except Exception as exc:
        server_logger.exception("Error getting gpio value %s " % shadow_name,
                                exc_info=exc)
        return None
Exemplo n.º 3
0
def read_gpio_by_name(name: str, chip: str = "aspeed-gpio") -> int:
    try:
        gpio = libgpio.GPIO(chip=chip, name=name)
        val = gpio.get_value()
        gpio.close()
        return int(val)
    except Exception as exc:
        server_logger.exception("Error getting gpio value %s " % name,
                                exc_info=exc)
        return None
Exemplo n.º 4
0
def get_pim_details():
    response = PimDetailResponse()
    for pimid in range(1, MAX_PIM_NUM + 1):
        try:
            response.addpimdata(pimid, _execute_peutil(pimid))
        except Exception as ex:
            server_logger.exception("Error getting pim data for pim: %d " %
                                    (pimid),
                                    exc_info=ex)
            response.addpimdata(pimid,
                                PimFailure(status="unknown", reason=str(ex)))
    return response.render()
Exemplo n.º 5
0
    async def middleware_handler(request):
        try:
            resp = await handler(request)
        except HTTPException as exc:
            resp = exc
        except Exception as exc:
            body = {
                "Information": {"reason": repr(exc)},
                "Actions": [],
                "Resources": [],
            }

            resp = HTTPInternalServerError(
                body=json.dumps(body), content_type="application/json"
            )
            server_logger.exception("Error handling request", exc_info=exc)
        return resp