Make errors singular

This commit is contained in:
Mubelotix
2025-08-05 16:58:21 +02:00
parent b5158e1e83
commit 1ff6da63e8
3 changed files with 22 additions and 22 deletions

View File

@ -421,8 +421,8 @@ InvalidChatCompletionSearchIndexUidParamPrompt , InvalidRequest , BAD_REQU
InvalidChatCompletionPreQueryPrompt , InvalidRequest , BAD_REQUEST ; InvalidChatCompletionPreQueryPrompt , InvalidRequest , BAD_REQUEST ;
// Webhooks // Webhooks
InvalidWebhooks , InvalidRequest , BAD_REQUEST ; InvalidWebhooks , InvalidRequest , BAD_REQUEST ;
InvalidWebhooksUrl , InvalidRequest , BAD_REQUEST ; InvalidWebhookUrl , InvalidRequest , BAD_REQUEST ;
InvalidWebhooksHeaders , InvalidRequest , BAD_REQUEST ; InvalidWebhookHeaders , InvalidRequest , BAD_REQUEST ;
ImmutableWebhook , InvalidRequest , BAD_REQUEST ; ImmutableWebhook , InvalidRequest , BAD_REQUEST ;
InvalidWebhookUuid , InvalidRequest , BAD_REQUEST ; InvalidWebhookUuid , InvalidRequest , BAD_REQUEST ;
WebhookNotFound , InvalidRequest , NOT_FOUND ; WebhookNotFound , InvalidRequest , NOT_FOUND ;

View File

@ -13,7 +13,7 @@ use deserr::{DeserializeError, Deserr, ValuePointerRef};
use index_scheduler::IndexScheduler; use index_scheduler::IndexScheduler;
use meilisearch_types::deserr::{immutable_field_error, DeserrJsonError}; use meilisearch_types::deserr::{immutable_field_error, DeserrJsonError};
use meilisearch_types::error::deserr_codes::{ use meilisearch_types::error::deserr_codes::{
BadRequest, InvalidWebhooksHeaders, InvalidWebhooksUrl, BadRequest, InvalidWebhookHeaders, InvalidWebhookUrl,
}; };
use meilisearch_types::error::{Code, ErrorCode, ResponseError}; use meilisearch_types::error::{Code, ErrorCode, ResponseError};
use meilisearch_types::keys::actions; use meilisearch_types::keys::actions;
@ -62,11 +62,11 @@ pub fn configure(cfg: &mut web::ServiceConfig) {
#[schema(rename_all = "camelCase")] #[schema(rename_all = "camelCase")]
pub(super) struct WebhookSettings { pub(super) struct WebhookSettings {
#[schema(value_type = Option<String>, example = "https://your.site/on-tasks-completed")] #[schema(value_type = Option<String>, example = "https://your.site/on-tasks-completed")]
#[deserr(default, error = DeserrJsonError<InvalidWebhooksUrl>)] #[deserr(default, error = DeserrJsonError<InvalidWebhookUrl>)]
#[serde(default)] #[serde(default)]
url: Setting<String>, url: Setting<String>,
#[schema(value_type = Option<BTreeMap<String, String>>, example = json!({"Authorization":"Bearer a-secret-token"}))] #[schema(value_type = Option<BTreeMap<String, String>>, example = json!({"Authorization":"Bearer a-secret-token"}))]
#[deserr(default, error = DeserrJsonError<InvalidWebhooksHeaders>)] #[deserr(default, error = DeserrJsonError<InvalidWebhookHeaders>)]
#[serde(default)] #[serde(default)]
headers: Setting<BTreeMap<String, Setting<String>>>, headers: Setting<BTreeMap<String, Setting<String>>>,
} }
@ -222,14 +222,14 @@ enum WebhooksError {
impl ErrorCode for WebhooksError { impl ErrorCode for WebhooksError {
fn error_code(&self) -> meilisearch_types::error::Code { fn error_code(&self) -> meilisearch_types::error::Code {
match self { match self {
MissingUrl(_) => meilisearch_types::error::Code::InvalidWebhooksUrl, MissingUrl(_) => meilisearch_types::error::Code::InvalidWebhookUrl,
TooManyWebhooks => meilisearch_types::error::Code::InvalidWebhooks, TooManyWebhooks => meilisearch_types::error::Code::InvalidWebhooks,
TooManyHeaders(_) => meilisearch_types::error::Code::InvalidWebhooksHeaders, TooManyHeaders(_) => meilisearch_types::error::Code::InvalidWebhookHeaders,
ImmutableWebhook(_) => meilisearch_types::error::Code::ImmutableWebhook, ImmutableWebhook(_) => meilisearch_types::error::Code::ImmutableWebhook,
WebhookNotFound(_) => meilisearch_types::error::Code::WebhookNotFound, WebhookNotFound(_) => meilisearch_types::error::Code::WebhookNotFound,
InvalidHeaderName(_, _) => meilisearch_types::error::Code::InvalidWebhooksHeaders, InvalidHeaderName(_, _) => meilisearch_types::error::Code::InvalidWebhookHeaders,
InvalidHeaderValue(_, _) => meilisearch_types::error::Code::InvalidWebhooksHeaders, InvalidHeaderValue(_, _) => meilisearch_types::error::Code::InvalidWebhookHeaders,
InvalidUrl(_, _) => meilisearch_types::error::Code::InvalidWebhooksUrl, InvalidUrl(_, _) => meilisearch_types::error::Code::InvalidWebhookUrl,
InvalidUuid(_) => meilisearch_types::error::Code::InvalidWebhookUuid, InvalidUuid(_) => meilisearch_types::error::Code::InvalidWebhookUuid,
} }
} }

View File

@ -349,9 +349,9 @@ async fn over_limits() {
snapshot!(value, @r#" snapshot!(value, @r#"
{ {
"message": "Too many headers for the webhook `[uuid]`. Please limit the number of headers to 200. Hint: To remove an already defined header set its value to `null`", "message": "Too many headers for the webhook `[uuid]`. Please limit the number of headers to 200. Hint: To remove an already defined header set its value to `null`",
"code": "invalid_webhooks_headers", "code": "invalid_webhook_headers",
"type": "invalid_request", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid_webhooks_headers" "link": "https://docs.meilisearch.com/errors#invalid_webhook_headers"
} }
"#); "#);
} }
@ -409,9 +409,9 @@ async fn create_and_patch() {
snapshot!(value, @r#" snapshot!(value, @r#"
{ {
"message": "The URL for the webhook `[uuid]` is missing.", "message": "The URL for the webhook `[uuid]` is missing.",
"code": "invalid_webhooks_url", "code": "invalid_webhook_url",
"type": "invalid_request", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid_webhooks_url" "link": "https://docs.meilisearch.com/errors#invalid_webhook_url"
} }
"#); "#);
@ -475,9 +475,9 @@ async fn create_and_patch() {
snapshot!(json_string!(value, { ".uuid" => "[uuid]" }), @r#" snapshot!(json_string!(value, { ".uuid" => "[uuid]" }), @r#"
{ {
"message": "The URL for the webhook `[uuid]` is missing.", "message": "The URL for the webhook `[uuid]` is missing.",
"code": "invalid_webhooks_url", "code": "invalid_webhook_url",
"type": "invalid_request", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid_webhooks_url" "link": "https://docs.meilisearch.com/errors#invalid_webhook_url"
} }
"#); "#);
} }
@ -492,9 +492,9 @@ async fn invalid_url_and_headers() {
snapshot!(value, @r#" snapshot!(value, @r#"
{ {
"message": "Invalid URL `not-a-valid-url`: relative URL without a base", "message": "Invalid URL `not-a-valid-url`: relative URL without a base",
"code": "invalid_webhooks_url", "code": "invalid_webhook_url",
"type": "invalid_request", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid_webhooks_url" "link": "https://docs.meilisearch.com/errors#invalid_webhook_url"
} }
"#); "#);
@ -509,9 +509,9 @@ async fn invalid_url_and_headers() {
snapshot!(value, @r#" snapshot!(value, @r#"
{ {
"message": "Invalid header name `invalid header name`: invalid HTTP header name", "message": "Invalid header name `invalid header name`: invalid HTTP header name",
"code": "invalid_webhooks_headers", "code": "invalid_webhook_headers",
"type": "invalid_request", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid_webhooks_headers" "link": "https://docs.meilisearch.com/errors#invalid_webhook_headers"
} }
"#); "#);
@ -526,9 +526,9 @@ async fn invalid_url_and_headers() {
snapshot!(value, @r#" snapshot!(value, @r#"
{ {
"message": "Invalid header value `authorization`: failed to parse header value", "message": "Invalid header value `authorization`: failed to parse header value",
"code": "invalid_webhooks_headers", "code": "invalid_webhook_headers",
"type": "invalid_request", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid_webhooks_headers" "link": "https://docs.meilisearch.com/errors#invalid_webhook_headers"
} }
"#); "#);
} }