Skip to content

Commit

Permalink
* Fix that assert errors in commands (eg. trying to unlink node with …
Browse files Browse the repository at this point in the history
…only 1 parent) does not display the actual error message in the notification area. Fixes #287.
  • Loading branch information
Venryx committed Apr 2, 2024
1 parent 80e6bdd commit fbc99c9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
42 changes: 33 additions & 9 deletions Packages/app-server/src/gql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::str::FromStr;
use std::sync::{Arc, Mutex};
use rust_shared::anyhow::{anyhow, bail};
use rust_shared::async_graphql::http::{playground_source, GraphQLPlaygroundConfig, graphiql_source};
use rust_shared::async_graphql::{Schema, MergedObject, MergedSubscription, ObjectType, Data, Result, SubscriptionType, EmptyMutation, EmptySubscription, Variables, extensions};
use rust_shared::async_graphql::{extensions, Data, EmptyMutation, EmptySubscription, MergedObject, MergedSubscription, ObjectType, Result, Schema, ServerError, SubscriptionType, Variables};
use rust_shared::bytes::Bytes;
use deadpool_postgres::{Pool, Manager};
use rust_shared::http_body_util::Full;
Expand All @@ -24,7 +24,7 @@ use rust_shared::utils::auth::jwt_utils_base::UserJWTData;
use rust_shared::utils::db::agql_ext::gql_general_extension::CustomExtensionCreator;
use rust_shared::utils::net::{body_to_str, full_body_from_str, new_hyper_client_http, AxumBody, HyperClient, HyperClient_};
use rust_shared::utils::type_aliases::JSONValue;
use rust_shared::{axum, serde_json, to_anyhow, tower, tower_http};
use rust_shared::{axum, serde_json, thiserror, to_anyhow, tower, tower_http};
use tower::make::Shared;
use tower::{Service, ServiceExt, BoxError, service_fn};
use tower_http::cors::{CorsLayer};
Expand Down Expand Up @@ -306,9 +306,14 @@ pub async fn extend_router(app: Router, storage_wrapper: AppStateArc) -> Router
pub async fn handle_gql_query_or_mutation(Extension(_client): Extension<HyperClient>, Extension(schema): Extension<RootSchema>, req: Request<AxumBody>) -> Response<AxumBody> {
let response_str = match have_own_graphql_handle_request(req, schema).await {
Ok(a) => a,
Err(err) => json!({
"error": format!("GQL error:{:?}", err),
}).to_string(),
Err(err) => match err {
HandleGQLRequestError::Early(err) => json!({
"errors": [{"message": err.to_string()}],
}).to_string(),
HandleGQLRequestError::Late(errors) => json!({
"errors": errors,
}).to_string(),
},
};

// send response (to frontend)
Expand All @@ -320,15 +325,34 @@ pub async fn handle_gql_query_or_mutation(Extension(_client): Extension<HyperCli
.unwrap();
response
}
pub async fn have_own_graphql_handle_request(req: Request<AxumBody>, schema: RootSchema) -> Result<String, Error> {

#[derive(thiserror::Error, Debug)]
pub enum HandleGQLRequestError {
#[error("Early gql error: {0:?}")]
Early(Error),
#[error("Late gql error: {0:?}")]
Late(Vec<ServerError>),
}
impl From<Error> for HandleGQLRequestError {
fn from(err: Error) -> Self {
HandleGQLRequestError::Early(err)
}
}
/*impl From<Vec<ServerError>> for HandleGQLRequestError {
fn from(errors: Vec<ServerError>) -> Self {
HandleGQLRequestError::Late(errors)
}
}*/

pub async fn have_own_graphql_handle_request(req: Request<AxumBody>, schema: RootSchema) -> Result<String, HandleGQLRequestError> {
use async_graphql::futures_util::TryFutureExt;

// retrieve auth-data/JWT and such from http-headers
let gql_data_from_http_request = get_gql_data_from_http_request(&req)?;

// read request's body (from frontend)
let req_as_str = body_to_str(req.into_body()).await?;
let req_as_json = JSONValue::from_str(&req_as_str)?;
let req_as_json = JSONValue::from_str(&req_as_str).map_err(to_anyhow)?;

// prepare request for graphql engine
//let gql_req = async_graphql::Request::new(req_as_str);
Expand Down Expand Up @@ -358,9 +382,9 @@ pub async fn have_own_graphql_handle_request(req: Request<AxumBody>, schema: Roo
}
},
}
let gql_response: async_graphql::Response = temp1.map_err(to_anyhow)?;
let gql_response: async_graphql::Response = temp1.map_err(HandleGQLRequestError::Late)?;
//let response_body: String = gql_response.data.to_string(); // this doesn't output valid json (eg. no quotes around keys)
let response_str: String = serde_json::to_string(&gql_response)?;
let response_str: String = serde_json::to_string(&gql_response).map_err(to_anyhow)?;

Ok(response_str)
}
Expand Down
3 changes: 2 additions & 1 deletion Packages/rust-shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ pub extern crate futures;
pub extern crate http_body_util;
pub extern crate hyper;
pub extern crate hyper_util;
pub extern crate postgres_protocol;
pub extern crate reqwest;
pub extern crate serde;
pub extern crate serde_json;
pub extern crate thiserror;
pub extern crate tokio;
pub extern crate tokio_postgres;
pub extern crate postgres_protocol;
pub extern crate tower;
pub extern crate tower_http;
pub extern crate tower_service;
Expand Down

0 comments on commit fbc99c9

Please sign in to comment.