Skip to content

Commit a66318b

Browse files
committed
make error-message in axum error page mandatory, remove AxumError::NoResults
1 parent 2912582 commit a66318b

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/web/error.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::borrow::Cow;
2+
13
use crate::{
24
db::PoolError,
35
web::{page::WebPage, releases::Search, AxumErrorPage, ErrorPage},
@@ -149,8 +151,8 @@ pub enum AxumNope {
149151
OwnerNotFound,
150152
#[error("Requested crate does not have specified version")]
151153
VersionNotFound,
152-
#[error("Search yielded no results")]
153-
NoResults,
154+
// #[error("Search yielded no results")]
155+
// NoResults,
154156
#[error("Internal server error")]
155157
InternalServerError,
156158
#[error("internal error")]
@@ -166,15 +168,15 @@ impl IntoResponse for AxumNope {
166168
// user tried to navigate to a resource (doc page/file) that doesn't exist
167169
AxumErrorPage {
168170
title: "Requested resource does not exist",
169-
message: Some("no such resource".into()),
171+
message: "no such resource".into(),
170172
status: StatusCode::NOT_FOUND,
171173
}
172174
.into_response()
173175
}
174176

175177
AxumNope::BuildNotFound => AxumErrorPage {
176178
title: "The requested build does not exist",
177-
message: Some("no such build".into()),
179+
message: "no such build".into(),
178180
status: StatusCode::NOT_FOUND,
179181
}
180182
.into_response(),
@@ -184,15 +186,15 @@ impl IntoResponse for AxumNope {
184186
// TODO: Display the attempted crate and a link to a search for said crate
185187
AxumErrorPage {
186188
title: "The requested crate does not exist",
187-
message: Some("no such crate".into()),
189+
message: "no such crate".into(),
188190
status: StatusCode::NOT_FOUND,
189191
}
190192
.into_response()
191193
}
192194

193195
AxumNope::OwnerNotFound => AxumErrorPage {
194196
title: "The requested owner does not exist",
195-
message: Some("no such owner".into()),
197+
message: "no such owner".into(),
196198
status: StatusCode::NOT_FOUND,
197199
}
198200
.into_response(),
@@ -202,19 +204,19 @@ impl IntoResponse for AxumNope {
202204
// TODO: Display the attempted crate and version
203205
AxumErrorPage {
204206
title: "The requested version does not exist",
205-
message: Some("no such version for this crate".into()),
207+
message: "no such version for this crate".into(),
206208
status: StatusCode::NOT_FOUND,
207209
}
208210
.into_response()
209211
}
210-
AxumNope::NoResults => {
211-
todo!("to be implemented when search-handler is migrated to axum")
212-
}
212+
// AxumNope::NoResults => {
213+
// todo!("to be implemented when search-handler is migrated to axum")
214+
// }
213215
AxumNope::InternalServerError => {
214216
// something went wrong, details should have been logged
215217
AxumErrorPage {
216218
title: "Internal server error",
217-
message: Some("internal server error".into()),
219+
message: "internal server error".into(),
218220
status: StatusCode::INTERNAL_SERVER_ERROR,
219221
}
220222
.into_response()
@@ -230,8 +232,8 @@ fn generate_internal_error_page<E: Into<anyhow::Error>>(error: E) -> impl IntoRe
230232

231233
let web_error = crate::web::AxumErrorPage {
232234
title: "Internal Server Error",
233-
message: ::std::option::Option::Some(::std::borrow::Cow::Owned(error.to_string())),
234-
status: ::http::StatusCode::INTERNAL_SERVER_ERROR,
235+
message: Cow::Owned(error.to_string()),
236+
status: StatusCode::INTERNAL_SERVER_ERROR,
235237
};
236238

237239
// TODO: check: does the sentry tower layer add the request as context?

src/web/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ pub(crate) struct AxumErrorPage {
685685
/// The title of the page
686686
pub title: &'static str,
687687
/// The error message, displayed as a description
688-
pub message: Option<Cow<'static, str>>,
688+
pub message: Cow<'static, str>,
689689
#[serde(skip)]
690690
pub status: StatusCode,
691691
}

0 commit comments

Comments
 (0)