Files
da567176ad Add support for retry-after header (#69)
* Parse retry-after from server's response

* Use latest linter version

---------

Co-authored-by: Robert-Stam <[email protected]>
2025-03-20 10:39:36 +01:00

46 lines
1.1 KiB
Go

package qdrant
import (
"fmt"
"strings"
)
//nolint:revive // The linter says qdrant.QdrantError stutters, but it's an apt name.
type QdrantError struct {
operationName string
context string
err error
}
// Error returns the error as string.
func (e *QdrantError) Error() string {
if e.context == "" {
return fmt.Sprintf("%s() failed: %v", e.operationName, e.err)
}
return fmt.Sprintf("%s() failed: %s: %v", e.operationName, e.context, e.err)
}
// Unwrap returns the inner error.
func (e *QdrantError) Unwrap() error {
return e.err
}
func newQdrantErr(err error, operationName string, contexts ...string) *QdrantError {
combinedContext := strings.Join(contexts, ": ")
return &QdrantError{
operationName: operationName,
err: err,
context: combinedContext,
}
}
//nolint:revive // The linter says QdrantResourceExhaustedError stutters, but it's an apt name.
type QdrantResourceExhaustedError struct {
Reason string
RetryAfterS int
}
func (e *QdrantResourceExhaustedError) Error() string {
return fmt.Sprintf("ResourceExhausted: %s, retry after %d seconds", e.Reason, e.RetryAfterS)
}