From bb5ef2a3fedf93d2be3c5e94059b135f177649d7 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Wed, 8 Mar 2023 14:53:14 -0500 Subject: [PATCH] 404 "None" job statuses from broken Python clients --- .../endpoints/tts/get_tts_inference_job_status.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/service/web/storyteller_web/src/http_server/endpoints/tts/get_tts_inference_job_status.rs b/crates/service/web/storyteller_web/src/http_server/endpoints/tts/get_tts_inference_job_status.rs index e172308a91..097de6f968 100644 --- a/crates/service/web/storyteller_web/src/http_server/endpoints/tts/get_tts_inference_job_status.rs +++ b/crates/service/web/storyteller_web/src/http_server/endpoints/tts/get_tts_inference_job_status.rs @@ -67,18 +67,21 @@ pub struct GetTtsInferenceStatusSuccessResponse { #[derive(Debug)] pub enum GetTtsInferenceStatusError { ServerError, + NotFound, } impl ResponseError for GetTtsInferenceStatusError { fn status_code(&self) -> StatusCode { match *self { - GetTtsInferenceStatusError::ServerError=> StatusCode::INTERNAL_SERVER_ERROR, + GetTtsInferenceStatusError::ServerError => StatusCode::INTERNAL_SERVER_ERROR, + GetTtsInferenceStatusError::NotFound => StatusCode::NOT_FOUND, } } fn error_response(&self) -> HttpResponse { let error_reason = match self { - GetTtsInferenceStatusError::ServerError => "server error".to_string(), + Self::ServerError => "server error".to_string(), + Self::NotFound => "not found".to_string(), }; to_simple_json_error(&error_reason, self.status_code()) @@ -98,13 +101,19 @@ pub async fn get_tts_inference_job_status_handler( path: Path, server_state: web::Data>) -> Result { + if path.token.trim() == "None" { + // NB: A bunch of Python clients use our API and can fail in this manner. + // This was a large traffic driver during the 2023-03-08 outage. + return Err(GetTtsInferenceStatusError::NotFound); + } + // NB: Lookup failure is Err(RowNotFound). // NB: Since this is publicly exposed, we don't query sensitive data. let maybe_status = get_tts_inference_job_status(&path.token, &server_state.mysql_pool).await; let record = match maybe_status { Ok(Some(record)) => record, - Ok(None) => return Err(GetTtsInferenceStatusError::ServerError), + Ok(None) => return Err(GetTtsInferenceStatusError::NotFound), Err(err) => { error!("tts job query error: {:?}", err); return Err(GetTtsInferenceStatusError::ServerError);