fix: adjust status code to http error code map (#3601)

* fix: adjust status code to http error code map

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

* update integration test

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

---------

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
This commit is contained in:
Ruihang Xia
2024-03-28 16:54:51 +08:00
committed by GitHub
parent d5ba2fcf9d
commit 06a90527a3
2 changed files with 13 additions and 7 deletions

View File

@@ -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()

View File

@@ -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::<ErrorResponse>(&res.text().await).unwrap();
// TODO(shuiyisong): fix this when return source err msg to client side