diff --git a/crates/api_clients/seedance2pro/src/requests/poll_orders/failure_reason.rs b/crates/api_clients/seedance2pro/src/requests/poll_orders/failure_reason.rs index c3c5506643..cdc537a1a8 100644 --- a/crates/api_clients/seedance2pro/src/requests/poll_orders/failure_reason.rs +++ b/crates/api_clients/seedance2pro/src/requests/poll_orders/failure_reason.rs @@ -15,7 +15,7 @@ impl FailureReason { /// First checks for exact string matches against known reasons, /// then falls back to case-insensitive substring matching. pub fn from_reason(reason: &str) -> Self { - let failure_type = classify_reason(reason); + let failure_type = FailureType::classify_text(reason); FailureReason { reason: reason.to_string(), failure_type, @@ -23,61 +23,3 @@ impl FailureReason { } } -fn classify_reason(reason: &str) -> FailureType { - // --- Exact matches first --- - match reason { - "Your uploaded image violates platform rules. Please modify and try again." => - return FailureType::RuleBansUserImage, - "Face detected in uploaded media. Please adjust your media and try again." => - return FailureType::RuleBansUserImageWithFaces, - "Your input text violates platform rules. Please modify and try again." => - return FailureType::RuleBansUserTextPrompt, - "Content violates platform rules. Please modify and try again." => - return FailureType::RuleBansUserContent, - "The generated video did not pass review. Credits will not be deducted." => - return FailureType::RuleBansGeneratedVideo, - "The generated audio violates platform rules. Please adjust your prompt or images and try again." => - return FailureType::RuleBansGeneratedAudio, - "The generated content violates platform rules. Please adjust your prompt or images and try again." => - return FailureType::RuleBansGeneratedContent, - "Video generation failed. Please try again." => - return FailureType::GenerationFailed, - "Generation timed out. Please try again." => - return FailureType::GenerationFailed, - "Server error. Please try again later." => - return FailureType::GenerationFailed, - "Your content could not be processed. Please try different images or adjust your prompt." => - return FailureType::GenerationFailed, - _ => {} - } - - // --- Substring matches (case-insensitive) --- - let lower = reason.to_lowercase(); - - if lower.contains("face detected") || lower.contains("ensure no faces") { - return FailureType::RuleBansUserImageWithFaces; - } - if lower.contains("uploaded image violates") { - return FailureType::RuleBansUserImage; - } - if lower.contains("input text violates") { - return FailureType::RuleBansUserTextPrompt; - } - if lower.contains("generated video") && lower.contains("not pass review") { - return FailureType::RuleBansGeneratedVideo; - } - if lower.contains("generated audio") && lower.contains("violates") { - return FailureType::RuleBansGeneratedAudio; - } - if lower.contains("generated content") && lower.contains("violates") { - return FailureType::RuleBansGeneratedContent; - } - if lower.contains("content violates") || lower.contains("platform rules") { - return FailureType::RuleBansUserContent; - } - if lower.contains("video generation failed") || lower.contains("timed out") || lower.contains("server error") { - return FailureType::GenerationFailed; - } - - FailureType::OtherUnknownReason -} diff --git a/crates/api_clients/seedance2pro/src/requests/poll_orders/failure_type.rs b/crates/api_clients/seedance2pro/src/requests/poll_orders/failure_type.rs index 92543536be..8817ef7eb2 100644 --- a/crates/api_clients/seedance2pro/src/requests/poll_orders/failure_type.rs +++ b/crates/api_clients/seedance2pro/src/requests/poll_orders/failure_type.rs @@ -1,3 +1,4 @@ + /// Categorized failure type for a Seedance2 Pro order. #[derive(Debug, Clone, PartialEq)] pub enum FailureType { @@ -20,3 +21,64 @@ pub enum FailureType { /// An unrecognized or absent failure reason. OtherUnknownReason, } + +impl FailureType { + pub fn classify_text(reason: &str) -> Self { + // --- Exact matches first --- + match reason { + "Your uploaded image violates platform rules. Please modify and try again." => + return Self::RuleBansUserImage, + "Face detected in uploaded media. Please adjust your media and try again." => + return Self::RuleBansUserImageWithFaces, + "Your input text violates platform rules. Please modify and try again." => + return Self::RuleBansUserTextPrompt, + "Content violates platform rules. Please modify and try again." => + return Self::RuleBansUserContent, + "The generated video did not pass review. Credits will not be deducted." => + return Self::RuleBansGeneratedVideo, + "The generated audio violates platform rules. Please adjust your prompt or images and try again." => + return Self::RuleBansGeneratedAudio, + "The generated content violates platform rules. Please adjust your prompt or images and try again." => + return Self::RuleBansGeneratedContent, + "Video generation failed. Please try again." => + return Self::GenerationFailed, + "Generation timed out. Please try again." => + return Self::GenerationFailed, + "Server error. Please try again later." => + return Self::GenerationFailed, + "Your content could not be processed. Please try different images or adjust your prompt." => + return Self::GenerationFailed, + _ => {} + } + + // --- Substring matches (case-insensitive) --- + let lower = reason.to_lowercase(); + + if lower.contains("face detected") || lower.contains("ensure no faces") { + return Self::RuleBansUserImageWithFaces; + } + if lower.contains("uploaded image violates") { + return Self::RuleBansUserImage; + } + if lower.contains("input text violates") { + return Self::RuleBansUserTextPrompt; + } + if lower.contains("generated video") && lower.contains("not pass review") { + return Self::RuleBansGeneratedVideo; + } + if lower.contains("generated audio") && lower.contains("violates") { + return Self::RuleBansGeneratedAudio; + } + if lower.contains("generated content") && lower.contains("violates") { + return Self::RuleBansGeneratedContent; + } + if lower.contains("content violates") || lower.contains("platform rules") { + return Self::RuleBansUserContent; + } + if lower.contains("video generation failed") || lower.contains("timed out") || lower.contains("server error") { + return Self::GenerationFailed; + } + + Self::OtherUnknownReason + } +}