mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-25 19:45:05 +08:00
Specialize authorized error message depending on config source
This commit is contained in:
parent
9b7764575b
commit
5aa6cb3600
@ -62,8 +62,18 @@ pub enum EmbedErrorKind {
|
|||||||
RestResponseDeserialization(std::io::Error),
|
RestResponseDeserialization(std::io::Error),
|
||||||
#[error("expected a response containing {0} embeddings, got only {1}")]
|
#[error("expected a response containing {0} embeddings, got only {1}")]
|
||||||
RestResponseEmbeddingCount(usize, usize),
|
RestResponseEmbeddingCount(usize, usize),
|
||||||
#[error("could not authenticate against embedding server{}", option_info(.0.as_deref(), "server replied with "))]
|
#[error("could not authenticate against {embedding} server{server_reply}{hint}", embedding=match *.1 {
|
||||||
RestUnauthorized(Option<String>),
|
ConfigurationSource::User => "embedding",
|
||||||
|
ConfigurationSource::OpenAi => "OpenAI",
|
||||||
|
ConfigurationSource::Ollama => "ollama"
|
||||||
|
},
|
||||||
|
server_reply=option_info(.0.as_deref(), "server replied with "),
|
||||||
|
hint=match *.1 {
|
||||||
|
ConfigurationSource::User => "\n - Hint: Check the `apiKey` parameter in the embedder configuration",
|
||||||
|
ConfigurationSource::OpenAi => "\n - Hint: Check the `apiKey` parameter in the embedder configuration, and the `MEILI_OPENAI_API_KEY` and `OPENAI_API_KEY` environment variables",
|
||||||
|
ConfigurationSource::Ollama => "\n - Hint: Check the `apiKey` parameter in the embedder configuration"
|
||||||
|
})]
|
||||||
|
RestUnauthorized(Option<String>, ConfigurationSource),
|
||||||
#[error("sent too many requests to embedding server{}", option_info(.0.as_deref(), "server replied with "))]
|
#[error("sent too many requests to embedding server{}", option_info(.0.as_deref(), "server replied with "))]
|
||||||
RestTooManyRequests(Option<String>),
|
RestTooManyRequests(Option<String>),
|
||||||
#[error("sent a bad request to embedding server{}{}",
|
#[error("sent a bad request to embedding server{}{}",
|
||||||
@ -136,8 +146,14 @@ impl EmbedError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn rest_unauthorized(error_response: Option<String>) -> EmbedError {
|
pub(crate) fn rest_unauthorized(
|
||||||
Self { kind: EmbedErrorKind::RestUnauthorized(error_response), fault: FaultSource::User }
|
error_response: Option<String>,
|
||||||
|
configuration_source: ConfigurationSource,
|
||||||
|
) -> EmbedError {
|
||||||
|
Self {
|
||||||
|
kind: EmbedErrorKind::RestUnauthorized(error_response, configuration_source),
|
||||||
|
fault: FaultSource::User,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn rest_too_many_requests(error_response: Option<String>) -> EmbedError {
|
pub(crate) fn rest_too_many_requests(error_response: Option<String>) -> EmbedError {
|
||||||
|
@ -275,7 +275,10 @@ fn check_response(
|
|||||||
Err(ureq::Error::Status(code, response)) => {
|
Err(ureq::Error::Status(code, response)) => {
|
||||||
let error_response: Option<String> = response.into_string().ok();
|
let error_response: Option<String> = response.into_string().ok();
|
||||||
Err(match code {
|
Err(match code {
|
||||||
401 => Retry::give_up(EmbedError::rest_unauthorized(error_response)),
|
401 => Retry::give_up(EmbedError::rest_unauthorized(
|
||||||
|
error_response,
|
||||||
|
configuration_source,
|
||||||
|
)),
|
||||||
429 => Retry::rate_limited(EmbedError::rest_too_many_requests(error_response)),
|
429 => Retry::rate_limited(EmbedError::rest_too_many_requests(error_response)),
|
||||||
400 => Retry::give_up(EmbedError::rest_bad_request(
|
400 => Retry::give_up(EmbedError::rest_bad_request(
|
||||||
error_response,
|
error_response,
|
||||||
|
Loading…
Reference in New Issue
Block a user