Coverage for volexport/api.py: 88%
33 statements
« prev ^ index » next coverage.py v7.10.4, created at 2025-08-20 14:19 +0000
« prev ^ index » next coverage.py v7.10.4, created at 2025-08-20 14:19 +0000
1from logging import getLogger
2from subprocess import SubprocessError
3from fastapi import FastAPI, Request
4from fastapi.responses import JSONResponse
5from .api_export import router as export_router
6from .api_volume import router as volume_router
8_log = getLogger(__name__)
9api = FastAPI()
10api.include_router(export_router)
11api.include_router(volume_router)
14@api.exception_handler(FileNotFoundError)
15def notfound(request: Request, exc: FileNotFoundError):
16 _log.info("not found: request=%s %s", request.method, request.url.path, exc_info=exc)
17 return JSONResponse(status_code=404, content=dict(detail="\n".join(exc.args)))
20@api.exception_handler(FileExistsError)
21def inuse(request: Request, exc: FileExistsError):
22 _log.info("file exists: request=%s %s", request.method, request.url.path, exc_info=exc)
23 return JSONResponse(status_code=400, content=dict(detail="\n".join(exc.args)))
26@api.exception_handler(NotImplementedError)
27def notimplemented(request: Request, exc: NotImplementedError):
28 _log.info("not implemented: request=%s %s", request.method, request.url.path, exc_info=exc)
29 return JSONResponse(status_code=501, content=dict(detail=str(exc)))
32@api.exception_handler(SubprocessError)
33def commanderror(request: Request, exc: SubprocessError):
34 _log.info("command error: request=%s %s", request.method, request.url.path, exc_info=exc)
35 return JSONResponse(status_code=500, content=dict(detail="internal error"))
38@api.exception_handler(TypeError)
39def typeerror(request: Request, exc: TypeError):
40 _log.info("internal error: request=%s %s", request.method, request.url.path, exc_info=exc)
41 return JSONResponse(status_code=500, content=dict(detail="internal error"))
44@api.get("/health")
45def health():
46 return {"status": "OK"}