Skip to content

Commit

Permalink
Remove ExplainError.
Browse files Browse the repository at this point in the history
It was a duplicate of `QueryError`.

Arguably, the explain endpoints could have always returned `QueryError`
or `MutationError` instead.
  • Loading branch information
SamirTalwar committed Aug 6, 2024
1 parent 4de7d49 commit 096af40
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 78 deletions.
4 changes: 2 additions & 2 deletions crates/sdk/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub trait Connector {
/// This function implements the [query/explain endpoint](https://hasura.github.io/ndc-spec/specification/explain.html)
/// from the NDC specification.
///
/// The [`ExplainError`] type is provided as a convenience to connector authors, to be used on
/// The [`QueryError`] type is provided as a convenience to connector authors, to be used on
/// error.
async fn query_explain(
configuration: &Self::Configuration,
Expand All @@ -91,7 +91,7 @@ pub trait Connector {
/// This function implements the [mutation/explain endpoint](https://hasura.github.io/ndc-spec/specification/explain.html)
/// from the NDC specification.
///
/// The [`ExplainError`] type is provided as a convenience to connector authors, to be used on
/// The [`MutationError`] type is provided as a convenience to connector authors, to be used on
/// error.
async fn mutation_explain(
configuration: &Self::Configuration,
Expand Down
76 changes: 0 additions & 76 deletions crates/sdk/src/connector/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,82 +280,6 @@ impl From<QueryError> for ErrorResponse {
}
}

/// Errors which occur when explaining a query.
///
/// See [`Connector::query_explain`, `Connector::mutation_explain`].
#[derive(Debug, thiserror::Error)]
pub enum ExplainError {
/// The request was invalid or did not match the
/// requirements of the specification. This indicates
/// an error with the client.
#[error("invalid request: {}", .0.message)]
InvalidRequest(models::ErrorResponse),
/// The request was well formed but was unable to be
/// followed due to semantic errors. This indicates
/// an error with the client.
#[error("unprocessable content: {}", .0.message)]
UnprocessableContent(models::ErrorResponse),
/// The request relies on an unsupported feature or
/// capability. This may indicate an error with the client,
/// or just an unimplemented feature.
#[error("unsupported operation: {}", .0.message)]
UnsupportedOperation(models::ErrorResponse),
}

impl ExplainError {
pub fn new_invalid_request<T: ToString>(message: &T) -> Self {
Self::InvalidRequest(models::ErrorResponse {
message: message.to_string(),
details: serde_json::Value::Null,
})
}

pub fn new_unprocessable_content<T: ToString>(message: &T) -> Self {
Self::UnprocessableContent(models::ErrorResponse {
message: message.to_string(),
details: serde_json::Value::Null,
})
}

pub fn new_unsupported_operation<T: ToString>(message: &T) -> Self {
Self::UnsupportedOperation(models::ErrorResponse {
message: message.to_string(),
details: serde_json::Value::Null,
})
}

#[must_use]
pub fn with_details(self, details: serde_json::Value) -> Self {
match self {
Self::InvalidRequest(models::ErrorResponse { message, .. }) => {
Self::InvalidRequest(models::ErrorResponse { message, details })
}
Self::UnprocessableContent(models::ErrorResponse { message, .. }) => {
Self::UnprocessableContent(models::ErrorResponse { message, details })
}
Self::UnsupportedOperation(models::ErrorResponse { message, .. }) => {
Self::UnsupportedOperation(models::ErrorResponse { message, details })
}
}
}
}

impl From<ExplainError> for ErrorResponse {
fn from(value: ExplainError) -> Self {
match value {
ExplainError::InvalidRequest(err) => {
ErrorResponse::from(err).with_status_code(StatusCode::BAD_REQUEST)
}
ExplainError::UnprocessableContent(err) => {
ErrorResponse::from(err).with_status_code(StatusCode::UNPROCESSABLE_ENTITY)
}
ExplainError::UnsupportedOperation(err) => {
ErrorResponse::from(err).with_status_code(StatusCode::NOT_IMPLEMENTED)
}
}
}
}

/// Errors which occur when executing a mutation.
///
/// See [`Connector::mutation`].
Expand Down

0 comments on commit 096af40

Please sign in to comment.