Download tools/server/exception_handler.py from SHJilan/s1-mini: direct link, hf CLI and curl.
- Browser
- Download file 729 Bytes
-
https://huggingface.co/spaces/SHJilan/s1-mini/resolve/main/tools/server/exception_handler.py
- Command line
-
hf download hf://spaces/SHJilan/s1-mini/tools/server/exception_handler.py
-
curl -L -o exception_handler.py https://huggingface.co/spaces/SHJilan/s1-mini/resolve/main/tools/server/exception_handler.py
729 Bytes
| import traceback | |
| from http import HTTPStatus | |
| from kui.asgi import HTTPException, JSONResponse | |
| class ExceptionHandler: | |
| async def http_exception_handler(self, exc: HTTPException): | |
| return JSONResponse( | |
| dict( | |
| statusCode=exc.status_code, | |
| message=exc.content, | |
| error=HTTPStatus(exc.status_code).phrase, | |
| ), | |
| exc.status_code, | |
| exc.headers, | |
| ) | |
| async def other_exception_handler(self, exc: Exception): | |
| traceback.print_exc() | |
| status = HTTPStatus.INTERNAL_SERVER_ERROR | |
| return JSONResponse( | |
| dict(statusCode=status, message=str(exc), error=status.phrase), | |
| status, | |
| ) | |