1use duroxide::providers::ProviderError;
2
3pub fn map_cosmosdb_error(operation: &str, status: u16, message: &str) -> ProviderError {
5 match status {
6 409 => ProviderError::retryable(operation, format!("CosmosDB conflict (409): {message}")),
8 429 => {
10 ProviderError::retryable(operation, format!("CosmosDB rate limited (429): {message}"))
11 }
12 408 => ProviderError::retryable(
14 operation,
15 format!("CosmosDB request timeout (408): {message}"),
16 ),
17 412 => ProviderError::retryable(
19 operation,
20 format!("CosmosDB precondition failed (412): {message}"),
21 ),
22 503 => ProviderError::retryable(
24 operation,
25 format!("CosmosDB service unavailable (503): {message}"),
26 ),
27 404 => ProviderError::permanent(operation, format!("CosmosDB not found (404): {message}")),
29 400 => {
31 ProviderError::permanent(operation, format!("CosmosDB bad request (400): {message}"))
32 }
33 413 => ProviderError::permanent(
35 operation,
36 format!("CosmosDB request too large (413): {message}"),
37 ),
38 s if s >= 500 => {
40 ProviderError::retryable(operation, format!("CosmosDB server error ({s}): {message}"))
41 }
42 s => ProviderError::permanent(operation, format!("CosmosDB client error ({s}): {message}")),
43 }
44}
45
46pub fn is_conflict(status: u16) -> bool {
48 status == 409
49}
50
51pub fn is_not_found(status: u16) -> bool {
53 status == 404
54}
55
56pub fn is_precondition_failed(status: u16) -> bool {
58 status == 412
59}