From 38f0e2ec15ed74fa7497fb52459537a4f53112dd Mon Sep 17 00:00:00 2001 From: Ryoga Saito Date: Sat, 2 Dec 2023 16:20:54 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=8F=E3=83=B3=E3=83=89=E3=83=AA=E3=83=B3?= =?UTF-8?q?=E3=82=B0=E3=82=92=E9=96=93=E9=81=95=E3=81=A3=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=82=8B=E9=83=A8=E5=88=86=E3=82=92=E4=BF=AE=E6=AD=A3=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bot/commands/redeploy.rs | 2 +- src/services/redeploy.rs | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/bot/commands/redeploy.rs b/src/bot/commands/redeploy.rs index 32f027e..d90b6b8 100644 --- a/src/bot/commands/redeploy.rs +++ b/src/bot/commands/redeploy.rs @@ -287,7 +287,7 @@ impl Bot { .await?; }, Err(err) => match err { - RedeployError::AnotherJobInQueue => { + RedeployError::AnotherJobInQueue(_) => { self.edit_response(component_interaction, |response| { response.content( "この問題は既に再展開リクエストが投げられています。再展開が完了してから再度お試しください。", diff --git a/src/services/redeploy.rs b/src/services/redeploy.rs index d0028e9..d84df88 100644 --- a/src/services/redeploy.rs +++ b/src/services/redeploy.rs @@ -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}")] @@ -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(),