Skip to content

Commit

Permalink
Add an 'UnprocessableContent' error
Browse files Browse the repository at this point in the history
  • Loading branch information
Gil Mizrahi committed Jan 4, 2024
1 parent f6723e9 commit d9689a2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 11 deletions.
15 changes: 15 additions & 0 deletions rust-connector-sdk/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ pub enum QueryError {
/// an error with the client.
#[error("invalid request: {0}")]
InvalidRequest(String),
/// The request was well formed but was unabled to be
/// followed due to semantic errors. This indicates
/// an error with the client.
#[error("unprocessable content: {0}")]
UnprocessableContent(String),
/// The request relies on an unsupported feature or
/// capability. This may indicate an error with the client,
/// or just an unimplemented feature.
Expand All @@ -108,6 +113,11 @@ pub enum ExplainError {
/// an error with the client.
#[error("invalid request: {0}")]
InvalidRequest(String),
/// The request was well formed but was unabled to be
/// followed due to semantic errors. This indicates
/// an error with the client.
#[error("unprocessable content: {0}")]
UnprocessableContent(String),
/// The request relies on an unsupported feature or
/// capability. This may indicate an error with the client,
/// or just an unimplemented feature.
Expand All @@ -127,6 +137,11 @@ pub enum MutationError {
/// an error with the client.
#[error("invalid request: {0}")]
InvalidRequest(String),
/// The request was well formed but was unabled to be
/// followed due to semantic errors. This indicates
/// an error with the client.
#[error("unprocessable content: {0}")]
UnprocessableContent(String),
/// The request relies on an unsupported feature or
/// capability. This may indicate an error with the client,
/// or just an unimplemented feature.
Expand Down
24 changes: 13 additions & 11 deletions rust-connector-sdk/src/default_main/v2_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,9 @@ pub async fn post_query<C: Connector>(
.await
.and_then(JsonResponse::into_value)
.map_err(|err| match err {
QueryError::InvalidRequest(message) | QueryError::UnsupportedOperation(message) => (
QueryError::InvalidRequest(message)
| QueryError::UnsupportedOperation(message)
| QueryError::UnprocessableContent(message) => (
StatusCode::BAD_REQUEST,
Json(ErrorResponse {
details: None,
Expand Down Expand Up @@ -417,16 +419,16 @@ pub async fn post_explain<C: Connector>(
.await
.and_then(JsonResponse::into_value)
.map_err(|err| match err {
ExplainError::InvalidRequest(message) | ExplainError::UnsupportedOperation(message) => {
(
StatusCode::BAD_REQUEST,
Json(ErrorResponse {
details: None,
message,
r#type: None,
}),
)
}
ExplainError::InvalidRequest(message)
| ExplainError::UnsupportedOperation(message)
| ExplainError::UnprocessableContent(message) => (
StatusCode::BAD_REQUEST,
Json(ErrorResponse {
details: None,
message,
r#type: None,
}),
),
ExplainError::Other(err) => (
StatusCode::BAD_REQUEST,
Json(ErrorResponse {
Expand Down
30 changes: 30 additions & 0 deletions rust-connector-sdk/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ pub async fn post_explain<C: Connector>(
)])),
}),
),
crate::connector::ExplainError::UnprocessableContent(detail) => (
StatusCode::UNPROCESSABLE_ENTITY,
Json(models::ErrorResponse {
message: "Unprocessable content".into(),
details: serde_json::Value::Object(serde_json::Map::from_iter([(
"detail".into(),
serde_json::Value::String(detail),
)])),
}),
),
crate::connector::ExplainError::UnsupportedOperation(detail) => (
StatusCode::NOT_IMPLEMENTED,
Json(models::ErrorResponse {
Expand Down Expand Up @@ -145,6 +155,16 @@ pub async fn post_mutation<C: Connector>(
)])),
}),
),
crate::connector::MutationError::UnprocessableContent(detail) => (
StatusCode::UNPROCESSABLE_ENTITY,
Json(models::ErrorResponse {
message: "Unprocessable content".into(),
details: serde_json::Value::Object(serde_json::Map::from_iter([(
"detail".into(),
serde_json::Value::String(detail),
)])),
}),
),
crate::connector::MutationError::UnsupportedOperation(detail) => (
StatusCode::NOT_IMPLEMENTED,
Json(models::ErrorResponse {
Expand Down Expand Up @@ -206,6 +226,16 @@ pub async fn post_query<C: Connector>(
)])),
}),
),
crate::connector::QueryError::UnprocessableContent(detail) => (
StatusCode::UNPROCESSABLE_ENTITY,
Json(models::ErrorResponse {
message: "Unprocessable content".into(),
details: serde_json::Value::Object(serde_json::Map::from_iter([(
"detail".into(),
serde_json::Value::String(detail),
)])),
}),
),
crate::connector::QueryError::UnsupportedOperation(detail) => (
StatusCode::NOT_IMPLEMENTED,
Json(models::ErrorResponse {
Expand Down

0 comments on commit d9689a2

Please sign in to comment.