Skip to content

Commit 9e1d3c2

Browse files
author
Devdutt Shenoi
committed
refactor: early fail on wrong json
1 parent e7a37b7 commit 9e1d3c2

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

src/handlers/http/logstream.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ pub async fn get_stream_info(stream_name: Path<String>) -> Result<impl Responder
589589

590590
pub async fn put_stream_hot_tier(
591591
stream_name: Path<String>,
592-
Json(json): Json<Value>,
592+
Json(mut hottier): Json<StreamHotTier>,
593593
) -> Result<impl Responder, StreamError> {
594594
let stream_name = stream_name.into_inner();
595595
if !STREAM_INFO.stream_exists(&stream_name) {
@@ -616,11 +616,6 @@ pub async fn put_stream_hot_tier(
616616
return Err(StreamError::HotTierNotEnabled(stream_name));
617617
}
618618

619-
let mut hottier: StreamHotTier = match serde_json::from_value(json) {
620-
Ok(hottier) => hottier,
621-
Err(err) => return Err(StreamError::InvalidHotTierConfig(err)),
622-
};
623-
624619
validator::hot_tier(&hottier.size.to_string())?;
625620

626621
STREAM_INFO.set_hot_tier(&stream_name, true)?;
@@ -836,8 +831,6 @@ pub mod error {
836831
"Hot tier is not enabled at the server config, cannot enable hot tier for stream {0}"
837832
)]
838833
HotTierNotEnabled(String),
839-
#[error("failed to enable hottier due to err: {0}")]
840-
InvalidHotTierConfig(serde_json::Error),
841834
#[error("Hot tier validation failed: {0}")]
842835
HotTierValidation(#[from] HotTierValidationError),
843836
#[error("{0}")]
@@ -875,7 +868,6 @@ pub mod error {
875868
err.status().unwrap_or(StatusCode::INTERNAL_SERVER_ERROR)
876869
}
877870
StreamError::HotTierNotEnabled(_) => StatusCode::BAD_REQUEST,
878-
StreamError::InvalidHotTierConfig(_) => StatusCode::BAD_REQUEST,
879871
StreamError::HotTierValidation(_) => StatusCode::BAD_REQUEST,
880872
StreamError::HotTierError(_) => StatusCode::INTERNAL_SERVER_ERROR,
881873
}

0 commit comments

Comments
 (0)