mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-06-04 22:30:37 +00:00
refactor: improve error code handling in status code conversion (#5851)
* refactor: improve error code handling in status code conversion * chore: apply suggestions from CR * fix: only hanlde client side thrown error * feat: introduce `DeadlineExceeded` * fix: exclude Code::Unknown from retry conditions
This commit is contained in:
@@ -772,9 +772,14 @@ impl IntoResponse for Error {
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts [StatusCode] to [HttpStatusCode].
|
||||
pub fn status_code_to_http_status(status_code: &StatusCode) -> HttpStatusCode {
|
||||
match status_code {
|
||||
StatusCode::Success | StatusCode::Cancelled => HttpStatusCode::OK,
|
||||
StatusCode::Success => HttpStatusCode::OK,
|
||||
|
||||
// When a request is cancelled by the client (e.g., by a client side timeout),
|
||||
// we should return a gateway timeout status code to the external client.
|
||||
StatusCode::Cancelled | StatusCode::DeadlineExceeded => HttpStatusCode::GATEWAY_TIMEOUT,
|
||||
|
||||
StatusCode::Unsupported
|
||||
| StatusCode::InvalidArguments
|
||||
|
||||
@@ -334,7 +334,7 @@ fn mysql_error_kind(status_code: &StatusCode) -> ErrorKind {
|
||||
StatusCode::Success => ErrorKind::ER_YES,
|
||||
StatusCode::Unknown | StatusCode::External => ErrorKind::ER_UNKNOWN_ERROR,
|
||||
StatusCode::Unsupported => ErrorKind::ER_NOT_SUPPORTED_YET,
|
||||
StatusCode::Cancelled => ErrorKind::ER_QUERY_INTERRUPTED,
|
||||
StatusCode::Cancelled | StatusCode::DeadlineExceeded => ErrorKind::ER_QUERY_INTERRUPTED,
|
||||
StatusCode::RuntimeResourcesExhausted => ErrorKind::ER_OUT_OF_RESOURCES,
|
||||
StatusCode::InvalidSyntax => ErrorKind::ER_SYNTAX_ERROR,
|
||||
StatusCode::RegionAlreadyExists | StatusCode::TableAlreadyExists => {
|
||||
|
||||
@@ -374,6 +374,7 @@ impl From<StatusCode> for PgErrorCode {
|
||||
StatusCode::Unsupported => PgErrorCode::Ec0A000,
|
||||
StatusCode::InvalidArguments => PgErrorCode::Ec22023,
|
||||
StatusCode::Cancelled => PgErrorCode::Ec57000,
|
||||
StatusCode::DeadlineExceeded => PgErrorCode::Ec57000,
|
||||
StatusCode::External => PgErrorCode::Ec58000,
|
||||
|
||||
StatusCode::Unknown
|
||||
|
||||
Reference in New Issue
Block a user