From 06a90527a3b793c87d9dbac2db7bb2a7efd94f01 Mon Sep 17 00:00:00 2001 From: Ruihang Xia Date: Thu, 28 Mar 2024 16:54:51 +0800 Subject: [PATCH] fix: adjust status code to http error code map (#3601) * fix: adjust status code to http error code map Signed-off-by: Ruihang Xia * update integration test Signed-off-by: Ruihang Xia --------- Signed-off-by: Ruihang Xia --- src/servers/src/http/error_result.rs | 18 ++++++++++++------ tests-integration/tests/http.rs | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/servers/src/http/error_result.rs b/src/servers/src/http/error_result.rs index d20de4f460..dac93c266c 100644 --- a/src/servers/src/http/error_result.rs +++ b/src/servers/src/http/error_result.rs @@ -84,6 +84,7 @@ impl IntoResponse for ErrorResponse { let status = StatusCode::from_u32(code).unwrap_or(StatusCode::Unknown); let status_code = match status { StatusCode::Success | StatusCode::Cancelled => HttpStatusCode::OK, + StatusCode::Unsupported | StatusCode::InvalidArguments | StatusCode::InvalidSyntax @@ -94,7 +95,9 @@ impl IntoResponse for ErrorResponse { | StatusCode::RegionNotFound | StatusCode::DatabaseNotFound | StatusCode::TableNotFound - | StatusCode::TableColumnNotFound => HttpStatusCode::BAD_REQUEST, + | StatusCode::TableColumnNotFound + | StatusCode::PlanQuery => HttpStatusCode::BAD_REQUEST, + StatusCode::PermissionDenied | StatusCode::AuthHeaderNotFound | StatusCode::InvalidAuthHeader @@ -102,16 +105,19 @@ impl IntoResponse for ErrorResponse { | StatusCode::UnsupportedPasswordType | StatusCode::UserPasswordMismatch | StatusCode::RegionReadonly => HttpStatusCode::UNAUTHORIZED, + StatusCode::AccessDenied => HttpStatusCode::FORBIDDEN, + + StatusCode::RateLimited => HttpStatusCode::TOO_MANY_REQUESTS, + + StatusCode::RegionNotReady + | StatusCode::RegionBusy + | StatusCode::StorageUnavailable => HttpStatusCode::SERVICE_UNAVAILABLE, + StatusCode::Internal | StatusCode::Unexpected | StatusCode::Unknown - | StatusCode::RegionNotReady - | StatusCode::RegionBusy - | StatusCode::RateLimited - | StatusCode::StorageUnavailable | StatusCode::RuntimeResourcesExhausted - | StatusCode::PlanQuery | StatusCode::EngineExecuteQuery => HttpStatusCode::INTERNAL_SERVER_ERROR, }; (status_code, resp).into_response() diff --git a/tests-integration/tests/http.rs b/tests-integration/tests/http.rs index abf207fd35..689eeeab8c 100644 --- a/tests-integration/tests/http.rs +++ b/tests-integration/tests/http.rs @@ -252,7 +252,7 @@ pub async fn test_sql_api(store_type: StorageType) { .get("/v1/sql?sql=select cpu, ts from demo limit 1;select cpu, ts from demo2 where ts > 0;") .send() .await; - assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR); + assert_eq!(res.status(), StatusCode::BAD_REQUEST); let body = serde_json::from_str::(&res.text().await).unwrap(); // TODO(shuiyisong): fix this when return source err msg to client side