diff --git a/src/auth.rs b/src/auth.rs
index b7688a3..c57185f 100644
--- a/src/auth.rs
+++ b/src/auth.rs
@@ -138,16 +138,7 @@ impl HttpContext for ConfiguredOidc {
Ok(_) => return Action::Pause,
Err(e) => {
warn!("token exchange failed: {}", e);
- self.send_http_response(
- 503,
- vec![("Cache-Control", "no-cache"),
- ("Content-Type", "text/html")],
- Some(b"
-
503
-
Token exchange failed
-
Please try again, delete your cookies or contact your system administrator.
-
"),
- );
+ self.show_error_page(503, "Token exchange failed", "Please try again, delete your cookies or contact your system administrator.");
}
}
return Action::Pause;
@@ -226,16 +217,10 @@ impl Context for ConfiguredOidc {
Err(e) => {
warn!("storing token in cookie failed: {}", e);
// Send a 503 if storing the token in the cookie failed
- self.send_http_response(
+ self.show_error_page(
503,
- vec![("Cache-Control", "no-cache"),
- ("Content-Type", "text/html")],
- Some(b"
-
503
-
Storing Token in Cookie failed
-
Please try again, delete your cookies or contact your system administrator.
-
",
- ),
+ "Storing Token in Cookie failed",
+ "Please try again, delete your cookies or contact your system administrator.",
);
}
}
diff --git a/src/error.rs b/src/error.rs
index 5e518cc..d93a919 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,6 +1,12 @@
+// proxy-wasm
+use proxy_wasm::traits::HttpContext;
+
// thiserror
use thiserror::Error;
+// crate
+use crate::auth::ConfiguredOidc;
+
/// Error type for the plugin
#[derive(Error, Debug)]
#[allow(clippy::enum_variant_names)]
@@ -59,3 +65,27 @@ pub enum PluginError {
#[error("state does not match")]
StateMismatchError,
}
+
+impl ConfiguredOidc {
+ pub fn show_error_page(&self, status_code: u32, title: &str, message: &str) {
+ let mut headers = vec![];
+ headers.push(("cache-control", "no-cache"));
+ headers.push(("content-type", "text/html"));
+
+ self.send_http_response(
+ status_code,
+ headers,
+ Some(
+ format!(
+ "",
+ status_code, title, message
+ )
+ .as_bytes(),
+ ),
+ );
+ }
+}