This commit is contained in:
Robin Appelman 2024-02-23 20:34:07 +01:00
commit 1d0d8fda57

View file

@ -27,8 +27,8 @@ enum ApiError {
SteamId(#[from] SteamIDError), SteamId(#[from] SteamIDError),
#[error(transparent)] #[error(transparent)]
Scrape(#[from] ScrapeError), Scrape(#[from] ScrapeError),
#[error("mallformed request")] #[error("malformed request")]
Mallformared(String), Malformed(String),
} }
impl IntoResponse for ApiError { impl IntoResponse for ApiError {
@ -38,7 +38,7 @@ impl IntoResponse for ApiError {
Self::SteamId(err) => { Self::SteamId(err) => {
(StatusCode::UNPROCESSABLE_ENTITY, format!("{:#}", err)).into_response() (StatusCode::UNPROCESSABLE_ENTITY, format!("{:#}", err)).into_response()
} }
Self::Mallformared(err) => { Self::Malformed(err) => {
(StatusCode::UNPROCESSABLE_ENTITY, format!("{:#}", err)).into_response() (StatusCode::UNPROCESSABLE_ENTITY, format!("{:#}", err)).into_response()
} }
Self::Scrape(ScrapeError::NotFound) => (StatusCode::NOT_FOUND, "").into_response(), Self::Scrape(ScrapeError::NotFound) => (StatusCode::NOT_FOUND, "").into_response(),
@ -116,12 +116,7 @@ async fn teams(
) -> Result<impl IntoResponse, ApiError> { ) -> Result<impl IntoResponse, ApiError> {
let mode = match GameMode::from_str(&format) { let mode = match GameMode::from_str(&format) {
Ok(mode) => mode, Ok(mode) => mode,
_ => { _ => return Err(ApiError::Malformed(format!("invalid game mode {}", format))),
return Err(ApiError::Mallformared(format!(
"invalid game mode {}",
format
)))
}
}; };
let response = state.client.teams(mode).await?; let response = state.client.teams(mode).await?;
Ok(Json(response)) Ok(Json(response))
@ -134,12 +129,7 @@ async fn transactions(
) -> Result<impl IntoResponse, ApiError> { ) -> Result<impl IntoResponse, ApiError> {
let mode = match GameMode::from_str(&format) { let mode = match GameMode::from_str(&format) {
Ok(mode) => mode, Ok(mode) => mode,
_ => { _ => return Err(ApiError::Malformed(format!("invalid game mode {}", format))),
return Err(ApiError::Mallformared(format!(
"invalid game mode {}",
format
)))
}
}; };
let response = state.client.transactions(mode).await?; let response = state.client.transactions(mode).await?;
Ok(Json(response)) Ok(Json(response))
@ -192,12 +182,7 @@ async fn map_history(
) -> Result<impl IntoResponse, ApiError> { ) -> Result<impl IntoResponse, ApiError> {
let mode = match GameMode::from_str(&format) { let mode = match GameMode::from_str(&format) {
Ok(mode) => mode, Ok(mode) => mode,
_ => { _ => return Err(ApiError::Malformed(format!("invalid game mode {}", format))),
return Err(ApiError::Mallformared(format!(
"invalid game mode {}",
format
)))
}
}; };
let response = state.client.map_history(mode).await?; let response = state.client.map_history(mode).await?;
Ok(Json(response)) Ok(Json(response))