This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/web/src/elements/messages/Middleware.ts
Jens Langhammer fc17580d9a web: only show message on server error
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
2021-03-29 17:36:52 +02:00

19 lines
659 B
TypeScript

import { Middleware, ResponseContext } from "authentik-api";
import { gettext } from "django";
import { MessageLevel } from "./Message";
import { showMessage } from "./MessageContainer";
export class MessageMiddleware implements Middleware {
post(context: ResponseContext): Promise<Response | void> {
if (context.response.status >= 500) {
showMessage({
level: MessageLevel.error,
message: gettext("API request failed"),
description: `${context.init.method} ${context.url}: ${context.response.status}`
});
}
return Promise.resolve(context.response);
}
}