Skip to content

Commit 014f149

Browse files
tellet-qcoszio
authored andcommitted
Parse retry-after header (#215)
* Parse retry-after header from server
1 parent 06a5846 commit 014f149

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/qdrant_client/error.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ pub enum QdrantError {
1111
status: tonic::Status,
1212
},
1313

14+
/// Qdrant server responded with a resource exhausted error
15+
#[error("Resource exhausted: {} {} {:?}, retry after {} seconds", .status.code(), .status.message(), .status.metadata(), .retry_after_seconds)]
16+
ResourceExhaustedError {
17+
/// gRPC status code
18+
status: tonic::Status,
19+
/// Retry after seconds
20+
retry_after_seconds: u64,
21+
},
22+
1423
/// Conversion of a Rust into an API type failed
1524
///
1625
/// Such error may include trying to convert a sparse vector into a dense vector.
@@ -42,6 +51,20 @@ pub enum QdrantError {
4251

4352
impl From<tonic::Status> for QdrantError {
4453
fn from(status: tonic::Status) -> Self {
54+
if status.code() == tonic::Code::ResourceExhausted {
55+
if let Some(retry_after_value) = status
56+
.metadata()
57+
.get("retry-after")
58+
.and_then(|v| v.to_str().ok())
59+
.and_then(|s| s.parse().ok())
60+
{
61+
return QdrantError::ResourceExhaustedError {
62+
status,
63+
retry_after_seconds: retry_after_value,
64+
};
65+
}
66+
}
67+
4568
QdrantError::ResponseError { status }
4669
}
4770
}

0 commit comments

Comments
 (0)