From f2825c64ee324ae63a1f4a28150b418673d2f2be Mon Sep 17 00:00:00 2001 From: Ji-Xinyou Date: Tue, 23 May 2023 16:35:31 +0800 Subject: [PATCH] fix(services/supabase): correctly set retryable * This PR parse the supabase statuscode more detailed and set the retryability correctly. Signed-off-by: Ji-Xinyou --- core/src/services/supabase/error.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/core/src/services/supabase/error.rs b/core/src/services/supabase/error.rs index 1acab7062c66..f9eb0b6e89c0 100644 --- a/core/src/services/supabase/error.rs +++ b/core/src/services/supabase/error.rs @@ -59,15 +59,18 @@ pub async fn parse_error(resp: Response) -> Result { // Return the error kind and whether it is retryable fn parse_supabase_error(err: &SupabaseError) -> (ErrorKind, bool) { let code = err.status_code.parse::().unwrap(); - if code == StatusCode::CONFLICT.as_u16() && err.error == "Duplicate" { - (ErrorKind::AlreadyExists, false) - } else if code == StatusCode::NOT_FOUND.as_u16() { - (ErrorKind::NotFound, false) - } else if code == StatusCode::FORBIDDEN.as_u16() { - (ErrorKind::PermissionDenied, false) - } else if code == StatusCode::PRECONDITION_FAILED.as_u16() { - (ErrorKind::ConditionNotMatch, false) - } else { - (ErrorKind::Unexpected, false) + let status_code = StatusCode::from_u16(code).unwrap(); + match status_code { + StatusCode::CONFLICT => (ErrorKind::AlreadyExists, false), + StatusCode::NOT_FOUND => (ErrorKind::NotFound, false), + StatusCode::FORBIDDEN => (ErrorKind::PermissionDenied, false), + StatusCode::PRECONDITION_FAILED | StatusCode::NOT_MODIFIED => { + (ErrorKind::ConditionNotMatch, false) + } + StatusCode::INTERNAL_SERVER_ERROR + | StatusCode::BAD_GATEWAY + | StatusCode::SERVICE_UNAVAILABLE + | StatusCode::GATEWAY_TIMEOUT => (ErrorKind::Unexpected, true), + _ => (ErrorKind::Unexpected, false), } }