line break after response, file extensions in url

This commit is contained in:
Paul Zinselmeyer 2023-10-18 19:46:57 +02:00
parent 72ec33636b
commit 7871d4c9f9
2 changed files with 9 additions and 7 deletions

View file

@ -31,13 +31,13 @@ pub enum Error {
impl IntoResponse for Error { impl IntoResponse for Error {
fn into_response(self) -> axum::response::Response { fn into_response(self) -> axum::response::Response {
match self { match self {
Self::PhraseInvalid => (StatusCode::BAD_REQUEST, "phrase is not valid"), Self::PhraseInvalid => (StatusCode::BAD_REQUEST, "url is not valid\n"),
Self::BinNotFound => (StatusCode::NOT_FOUND, "bin does not exist"), Self::BinNotFound => (StatusCode::NOT_FOUND, "bin does not exist\n"),
Self::DataFileExists => (StatusCode::CONFLICT, "bin already has data"), Self::DataFileExists => (StatusCode::CONFLICT, "bin already contains data\n"),
Self::ParseTtl => (StatusCode::BAD_REQUEST, "invalid ttl class"), Self::ParseTtl => (StatusCode::BAD_REQUEST, "invalid ttl class\n"),
_ => { _ => {
error!("{:?}", self); error!("{:?}", self);
(StatusCode::INTERNAL_SERVER_ERROR, "internal server error") (StatusCode::INTERNAL_SERVER_ERROR, "internal server error\n")
} }
} }
.into_response() .into_response()

View file

@ -33,10 +33,12 @@ impl FromStr for Phrase {
type Err = Error; type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
if s.chars().any(|x| !x.is_ascii_alphanumeric()) { if s.chars().any(|x| !x.is_ascii_alphanumeric() && x != '.') {
Err(Error::PhraseInvalid) Err(Error::PhraseInvalid)
} else { } else {
Ok(Self(s.to_string())) Ok(Self(
s.chars().take(s.find('.').unwrap_or(s.len())).collect(),
))
} }
} }
} }