11use std:: { sync:: Arc , vec} ;
22
3- use graphql_tools:: validation:: utils:: ValidationError ;
3+ use graphql_tools:: { parser :: query :: MinifyError , validation:: utils:: ValidationError } ;
44use hive_router_plan_executor:: {
55 execution:: { error:: PlanExecutionError , jwt_forward:: JwtForwardingError } ,
66 headers:: errors:: HeaderRuleRuntimeError ,
@@ -69,13 +69,13 @@ pub enum PipelineError {
6969 FailedToParseExtensions ( sonic_rs:: Error ) ,
7070 #[ error( "Failed to parse GraphQL operation: {0}" ) ]
7171 #[ strum( serialize = "GRAPHQL_PARSE_FAILED" ) ]
72- FailedToParseOperation ( #[ from] Arc < graphql_tools:: parser:: query:: ParseError > ) ,
72+ FailedToParseOperation ( #[ from] graphql_tools:: parser:: query:: ParseError ) ,
7373 #[ error( "Failed to minify parsed GraphQL operation: {0}" ) ]
7474 #[ strum( serialize = "GRAPHQL_PARSE_MINIFY_FAILED" ) ]
75- FailedToMinifyParsedOperation ( String ) ,
75+ FailedToMinifyParsedOperation ( # [ from ] MinifyError ) ,
7676 #[ error( "Failed to normalize GraphQL operation" ) ]
7777 #[ strum( serialize = "OPERATION_RESOLUTION_FAILURE" ) ]
78- NormalizationError ( #[ from] Arc < NormalizationError > ) ,
78+ NormalizationError ( #[ from] NormalizationError ) ,
7979 #[ error( "Failed to collect GraphQL variables: {0}" ) ]
8080 #[ strum( serialize = "BAD_USER_INPUT" ) ]
8181 VariablesCoercionError ( String ) ,
@@ -90,7 +90,7 @@ pub enum PipelineError {
9090 PlanExecutionError ( #[ from] PlanExecutionError ) ,
9191 #[ error( "Failed to produce a plan: {0}" ) ]
9292 #[ strum( serialize = "QUERY_PLAN_BUILD_FAILED" ) ]
93- PlannerError ( #[ from] Arc < PlannerError > ) ,
93+ PlannerError ( #[ from] PlannerError ) ,
9494 #[ error( transparent) ]
9595 #[ strum( serialize = "OVERRIDE_LABEL_EVALUATION_FAILED" ) ]
9696 LabelEvaluationError ( #[ from] LabelEvaluationError ) ,
@@ -143,30 +143,9 @@ pub enum PipelineError {
143143 #[ error( "No supergraph available yet, unable to process request" ) ]
144144 #[ strum( serialize = "NO_SUPERGRAPH_AVAILABLE" ) ]
145145 NoSupergraphAvailable ,
146- }
147-
148- #[ derive( Clone , Debug , thiserror:: Error ) ]
149- pub enum ParserCacheError {
150- #[ error( "Failed to parse GraphQL operation: {0}" ) ]
151- ParseError ( Arc < graphql_tools:: parser:: query:: ParseError > ) ,
152- #[ error( "Failed to minify parsed GraphQL operation: {0}" ) ]
153- MinifyError ( String ) ,
154- #[ error( "Validation errors" ) ]
155- ValidationErrors ( Arc < Vec < ValidationError > > ) ,
156- }
157146
158- impl From < Arc < ParserCacheError > > for PipelineError {
159- fn from ( value : Arc < ParserCacheError > ) -> Self {
160- match value. as_ref ( ) {
161- ParserCacheError :: ParseError ( err) => PipelineError :: FailedToParseOperation ( err. clone ( ) ) ,
162- ParserCacheError :: MinifyError ( err) => {
163- PipelineError :: FailedToMinifyParsedOperation ( err. clone ( ) )
164- }
165- ParserCacheError :: ValidationErrors ( errs) => {
166- PipelineError :: ValidationErrors ( errs. clone ( ) )
167- }
168- }
169- }
147+ #[ error( transparent) ]
148+ PipelineErrorArc ( #[ from] Arc < PipelineError > ) ,
170149}
171150
172151impl PipelineError {
@@ -175,13 +154,15 @@ impl PipelineError {
175154 Self :: JwtError ( err) => err. error_code ( ) ,
176155 Self :: PlanExecutionError ( err) => err. error_code ( ) ,
177156 Self :: ReadBodyStreamError ( err) => err. error_code ( ) ,
157+ Self :: PipelineErrorArc ( err) => err. graphql_error_code ( ) ,
178158 _ => self . into ( ) ,
179159 }
180160 }
181161
182162 pub fn graphql_error_message ( & self ) -> String {
183163 match self {
184164 Self :: PlannerError ( _) => "Unexpected error" . to_string ( ) ,
165+ Self :: PipelineErrorArc ( err) => err. graphql_error_message ( ) ,
185166 _ => self . to_string ( ) ,
186167 }
187168 }
@@ -226,6 +207,7 @@ impl PipelineError {
226207 ( Self :: HeaderPropagation ( _) , _) => StatusCode :: INTERNAL_SERVER_ERROR ,
227208 ( Self :: QueryPlanSerializationFailed ( _) , _) => StatusCode :: INTERNAL_SERVER_ERROR ,
228209 ( Self :: NoSupergraphAvailable , _) => StatusCode :: SERVICE_UNAVAILABLE ,
210+ ( Self :: PipelineErrorArc ( err) , _) => err. default_status_code ( prefer_ok) ,
229211 }
230212 }
231213}
@@ -237,10 +219,13 @@ struct FailedExecutionResult {
237219
238220#[ inline]
239221pub fn handle_pipeline_error (
240- err : PipelineError ,
222+ err : & PipelineError ,
241223 shared_state : & RouterSharedState ,
242224 response_mode : & ResponseMode ,
243225) -> web:: HttpResponse {
226+ if let PipelineError :: PipelineErrorArc ( inner) = & err {
227+ return handle_pipeline_error ( inner, shared_state, response_mode) ;
228+ }
244229 let single_content_type = response_mode. single_content_type ( ) ;
245230
246231 let prefer_ok = response_mode. prefer_status_ok_for_errors ( ) ;
0 commit comments