Skip to content

Commit

Permalink
fix(hubble): do not discard hasura errors (#733)
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiserKarel authored Sep 25, 2023
1 parent d838509 commit fb7839c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions hubble/src/hasura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ pub struct HasuraDataStore {
}

impl Datastore for HasuraDataStore {
/// Performs a GraphQL post request (which may query or mutate).
/// It injects the x-hasura-admin-secret header.
///
/// # Errors
/// - On network related errors.
/// - If the graphql endpoint populates the errors field.
#[allow(clippy::manual_async_fn)]
fn do_post<Q: GraphQLQuery>(
&self,
Expand All @@ -41,6 +47,16 @@ impl Datastore for HasuraDataStore {
.await?
.json()
.await?;

// GraphQL APIs return errors as an error field in the JSON. We convert the errors to the
// error variant.
if let Some(err) = response
.errors
.as_ref()
.map(|errors| color_eyre::eyre::eyre!("api returned error: {:?}", errors))
{
return Err(err);
}
Ok(response)
}
}
Expand Down

0 comments on commit fb7839c

Please sign in to comment.