Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/servers/src/http/error_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -94,24 +95,29 @@ 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
| StatusCode::UserNotFound
| 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()
Expand Down
2 changes: 1 addition & 1 deletion tests-integration/tests/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down