line break after response, file extensions in url
This commit is contained in:
parent
72ec33636b
commit
7871d4c9f9
2 changed files with 9 additions and 7 deletions
10
src/error.rs
10
src/error.rs
|
@ -31,13 +31,13 @@ pub enum Error {
|
|||
impl IntoResponse for Error {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
match self {
|
||||
Self::PhraseInvalid => (StatusCode::BAD_REQUEST, "phrase is not valid"),
|
||||
Self::BinNotFound => (StatusCode::NOT_FOUND, "bin does not exist"),
|
||||
Self::DataFileExists => (StatusCode::CONFLICT, "bin already has data"),
|
||||
Self::ParseTtl => (StatusCode::BAD_REQUEST, "invalid ttl class"),
|
||||
Self::PhraseInvalid => (StatusCode::BAD_REQUEST, "url is not valid\n"),
|
||||
Self::BinNotFound => (StatusCode::NOT_FOUND, "bin does not exist\n"),
|
||||
Self::DataFileExists => (StatusCode::CONFLICT, "bin already contains data\n"),
|
||||
Self::ParseTtl => (StatusCode::BAD_REQUEST, "invalid ttl class\n"),
|
||||
_ => {
|
||||
error!("{:?}", self);
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, "internal server error")
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, "internal server error\n")
|
||||
}
|
||||
}
|
||||
.into_response()
|
||||
|
|
|
@ -33,10 +33,12 @@ impl FromStr for Phrase {
|
|||
type Err = Error;
|
||||
|
||||
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)
|
||||
} else {
|
||||
Ok(Self(s.to_string()))
|
||||
Ok(Self(
|
||||
s.chars().take(s.find('.').unwrap_or(s.len())).collect(),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue