Catch panics in query engine request handler
@@ -25,9 +25,15 @@ impl RequestHandler for GraphQlRequestHandler {
where
S: Into<PrismaRequest<Self::Body>> + Send + Sync + 'static,
{
- let responses = match handle_graphql_query(req.into(), ctx).await {
- Ok(responses) => responses,
- Err(err) => vec![err.into()],
+ use std::panic::AssertUnwindSafe;
+ use futures::FutureExt;
+ use user_facing_errors::{UnknownError, Error};
+
+ let responses = match AssertUnwindSafe(handle_graphql_query(req.into(), ctx)).catch_unwind().await {
+ Ok(Ok(responses)) => responses,
+ Ok(Err(err)) => vec![err.into()],
+ // panicked
+ Err(err) => vec![response_ir::Response::Error(response_ir::ResponseError::from(Error::Unknown(UnknownError::from_panic_payload(&err))))],
};
json::serialize(responses)
