root: remove asgi error handler
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
90ecb1af7f
commit
95efd47f65
|
@ -13,7 +13,6 @@ from defusedxml import defuse_stdlib
|
||||||
from django.core.asgi import get_asgi_application
|
from django.core.asgi import get_asgi_application
|
||||||
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
|
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
|
||||||
|
|
||||||
from authentik.root.asgi.error_handler import ASGIErrorHandler
|
|
||||||
from authentik.root.asgi.logger import ASGILogger
|
from authentik.root.asgi.logger import ASGILogger
|
||||||
|
|
||||||
# DJANGO_SETTINGS_MODULE is set in gunicorn.conf.py
|
# DJANGO_SETTINGS_MODULE is set in gunicorn.conf.py
|
||||||
|
@ -24,16 +23,14 @@ django.setup()
|
||||||
# pylint: disable=wrong-import-position
|
# pylint: disable=wrong-import-position
|
||||||
from authentik.root import websocket # noqa # isort:skip
|
from authentik.root import websocket # noqa # isort:skip
|
||||||
|
|
||||||
application = ASGIErrorHandler(
|
application = ASGILogger(
|
||||||
ASGILogger(
|
guarantee_single_callable(
|
||||||
guarantee_single_callable(
|
SentryAsgiMiddleware(
|
||||||
SentryAsgiMiddleware(
|
ProtocolTypeRouter(
|
||||||
ProtocolTypeRouter(
|
{
|
||||||
{
|
"http": get_asgi_application(),
|
||||||
"http": get_asgi_application(),
|
"websocket": URLRouter(websocket.websocket_urlpatterns),
|
||||||
"websocket": URLRouter(websocket.websocket_urlpatterns),
|
}
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
"""ASGI Error handler"""
|
|
||||||
from structlog.stdlib import get_logger
|
|
||||||
|
|
||||||
from authentik.root.asgi.types import ASGIApp, Receive, Scope, Send
|
|
||||||
|
|
||||||
LOGGER = get_logger("authentik.asgi")
|
|
||||||
|
|
||||||
|
|
||||||
class ASGIErrorHandler:
|
|
||||||
"""ASGI Error handler"""
|
|
||||||
|
|
||||||
app: ASGIApp
|
|
||||||
|
|
||||||
def __init__(self, app: ASGIApp):
|
|
||||||
self.app = app
|
|
||||||
|
|
||||||
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
|
|
||||||
try:
|
|
||||||
return await self.app(scope, receive, send)
|
|
||||||
except Exception as exc: # pylint: disable=broad-except
|
|
||||||
LOGGER.warning("Fatal ASGI exception", exc=exc)
|
|
||||||
return await self.error_handler(scope, send)
|
|
||||||
|
|
||||||
async def error_handler(self, scope: Scope, send: Send) -> None:
|
|
||||||
"""Return a generic error message"""
|
|
||||||
if scope.get("scheme", "http") == "http":
|
|
||||||
return await send(
|
|
||||||
{
|
|
||||||
"type": "http.request",
|
|
||||||
"body": b"Internal server error",
|
|
||||||
"more_body": False,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return await send(
|
|
||||||
{
|
|
||||||
"type": "websocket.close",
|
|
||||||
}
|
|
||||||
)
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
// NewProxyErrorHandler creates a ProxyErrorHandler using the template given.
|
// NewProxyErrorHandler creates a ProxyErrorHandler using the template given.
|
||||||
func NewProxyErrorHandler(errorTemplate *template.Template) func(http.ResponseWriter, *http.Request, error) {
|
func NewProxyErrorHandler(errorTemplate *template.Template) func(http.ResponseWriter, *http.Request, error) {
|
||||||
return func(rw http.ResponseWriter, req *http.Request, proxyErr error) {
|
return func(rw http.ResponseWriter, req *http.Request, proxyErr error) {
|
||||||
log.Errorf("Error proxying to upstream server: %v", proxyErr)
|
log.WithError(proxyErr).Warning("Error proxying to upstream server")
|
||||||
rw.WriteHeader(http.StatusBadGateway)
|
rw.WriteHeader(http.StatusBadGateway)
|
||||||
data := struct {
|
data := struct {
|
||||||
Title string
|
Title string
|
||||||
|
|
Reference in New Issue