Skip to content

Commit

Permalink
ハンドリングを間違っている部分を修正した
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryoga Saito committed Dec 2, 2023
1 parent e815a28 commit 38f0e2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/bot/commands/redeploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl Bot {
.await?;
},
Err(err) => match err {
RedeployError::AnotherJobInQueue => {
RedeployError::AnotherJobInQueue(_) => {
self.edit_response(component_interaction, |response| {
response.content(
"この問題は既に再展開リクエストが投げられています。再展開が完了してから再度お試しください。",
Expand Down
14 changes: 9 additions & 5 deletions src/services/redeploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub enum RedeployError {
#[error("invalid parameters")]
InvalidParameters,
#[error("another job is in queue")]
AnotherJobInQueue,
AnotherJobInQueue(String),

// serde_jsonでserialize/deserializeに失敗した時に出るエラー
#[error("serde_json error: {0}")]
Expand Down Expand Up @@ -150,12 +150,16 @@ impl RedeployService for RState {
problem_code: response.prob_id,
})
},
StatusCode::BAD_REQUEST => {
let data = String::from_utf8(response.bytes().await?.to_vec())
.map_err(|err| RedeployError::Unexpected(Box::new(err)))?;

// ref: https://github.com/ictsc/rstate/blob/main/pkg/server/handler/status.go#L121-L124
StatusCode::BAD_REQUEST => Err(RedeployError::InvalidParameters),
if data == "BadRequest!" {
return Err(RedeployError::InvalidParameters);
}

// ref: https://github.com/ictsc/rstate/blob/main/pkg/server/handler/status.go#L145C65-L148
StatusCode::CONFLICT => Err(RedeployError::AnotherJobInQueue),
Err(RedeployError::AnotherJobInQueue(data))
},

_ => Err(RedeployError::Unexpected(
anyhow::anyhow!("unexpected status code: {}", response.status()).into(),
Expand Down

0 comments on commit 38f0e2e

Please sign in to comment.