summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToby Vincent <tobyv@tobyvin.dev>2024-04-03 16:55:25 -0500
committerToby Vincent <tobyv@tobyvin.dev>2024-04-03 16:55:25 -0500
commitaf3cd0647bd5478fdb28b4aea552e999c4108ecb (patch)
tree9b182932bb9ecd74d7320d6e2116e2e383fb3ed7
parent6c9a5896f1d1b1bb3175dda4ef5232bc5245898f (diff)
fix: properly handle invalid header value errors
-rw-r--r--src/error.rs3
-rw-r--r--src/routes/login.rs8
2 files changed, 7 insertions, 4 deletions
diff --git a/src/error.rs b/src/error.rs
index 48360de..6a32438 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -20,6 +20,9 @@ pub enum Error {
#[error("Http error: {0}")]
Http(#[from] axum::http::Error),
+ #[error("Header error: {0}")]
+ Header(#[from] axum::http::header::InvalidHeaderValue),
+
#[error("Json error: {0}")]
Json(#[from] serde_json::Error),
diff --git a/src/routes/login.rs b/src/routes/login.rs
index 2441a21..a580873 100644
--- a/src/routes/login.rs
+++ b/src/routes/login.rs
@@ -60,7 +60,7 @@ impl Login {
response
.headers_mut()
- .insert(SET_COOKIE, cookie.to_string().parse().unwrap());
+ .insert(SET_COOKIE, cookie.to_string().parse()?);
Ok(response)
}
@@ -72,7 +72,7 @@ pub struct Logout;
impl Logout {
#[tracing::instrument]
- pub async fn get(self) -> impl IntoResponse {
+ pub async fn get(self) -> Result<impl IntoResponse, Error> {
let cookie = Cookie::build(("token", ""))
.path("/")
.max_age(time::Duration::hours(-1))
@@ -84,9 +84,9 @@ impl Logout {
response
.headers_mut()
- .insert(SET_COOKIE, cookie.to_string().parse().unwrap());
+ .insert(SET_COOKIE, cookie.to_string().parse()?);
- response
+ Ok(response)
}
}