Created
May 4, 2022 01:45
-
-
Save aliwo/83230b2be15833042038be6a4128657f to your computer and use it in GitHub Desktop.
catching exception
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from starlette.middleware.base import BaseHTTPMiddleware | |
from starlette.responses import JSONResponse | |
class UnknownExceptionMiddleware(BaseHTTPMiddleware): # https://www.starlette.io/middleware/#basehttpmiddleware | |
def __init__(self, app): | |
super().__init__(app) | |
async def dispatch(self, request, call_next): | |
try: | |
return await call_next(request) | |
except Exception: | |
print("예상치 못한 에러 발생, 로그 찍어야 됩니다.") | |
return JSONResponse( | |
message={ | |
"message": "Unknown Server Error", | |
}, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment