hive_router_plan_executor/executors/
error.rs1use hive_router_internal::expressions::vrl::prelude::ExpressionError;
2
3use crate::response::graphql_error::{GraphQLError, GraphQLErrorExtensions};
4
5#[derive(thiserror::Error, Debug, Clone)]
6pub enum SubgraphExecutorError {
7 #[error("Failed to parse endpoint \"{0}\" as URI: {1}")]
8 EndpointParseFailure(String, String),
9 #[error("Failed to compile VRL expression for subgraph '{0}'. Please check your VRL expression for syntax errors. Diagnostic: {1}")]
10 EndpointExpressionBuild(String, String),
11 #[error("Failed to resolve VRL expression for subgraph '{0}'. Runtime error: {1}")]
12 EndpointExpressionResolutionFailure(String, String),
13 #[error("VRL expression for subgraph '{0}' resolved to a non-string value.")]
14 EndpointExpressionWrongType(String),
15 #[error("Static endpoint not found for subgraph '{0}'. This is an internal error and should not happen.")]
16 StaticEndpointNotFound(String),
17 #[error("Failed to build request to subgraph \"{0}\": {1}")]
18 RequestBuildFailure(String, String),
19 #[error("Failed to send request to subgraph \"{0}\": {1}")]
20 RequestFailure(String, String),
21 #[error("Failed to serialize variable \"{0}\": {1}")]
22 VariablesSerializationFailure(String, String),
23 #[error("Failed to compile VRL expression for timeout for subgraph '{0}'. Please check your VRL expression for syntax errors. Diagnostic: {1}")]
24 RequestTimeoutExpressionBuild(String, String),
25 #[error("Failed to resolve VRL expression for timeout for subgraph '{0}'. Runtime error: {1}")]
26 TimeoutExpressionResolution(String, String),
27 #[error("Request to subgraph \"{0}\" timed out after {1} milliseconds")]
28 RequestTimeout(String, u128),
29}
30
31impl From<SubgraphExecutorError> for GraphQLError {
32 fn from(error: SubgraphExecutorError) -> Self {
33 GraphQLError {
34 message: "Internal server error".to_string(),
35 locations: None,
36 path: None,
37 extensions: GraphQLErrorExtensions::new_from_code(error.error_code()),
38 }
39 }
40}
41
42impl SubgraphExecutorError {
43 pub fn new_endpoint_expression_resolution_failure(
44 subgraph_name: String,
45 error: ExpressionError,
46 ) -> Self {
47 SubgraphExecutorError::EndpointExpressionResolutionFailure(subgraph_name, error.to_string())
48 }
49
50 pub fn error_code(&self) -> &'static str {
51 match self {
52 SubgraphExecutorError::EndpointParseFailure(_, _) => "SUBGRAPH_ENDPOINT_PARSE_FAILURE",
53 SubgraphExecutorError::EndpointExpressionBuild(_, _) => {
54 "SUBGRAPH_ENDPOINT_EXPRESSION_BUILD_FAILURE"
55 }
56 SubgraphExecutorError::EndpointExpressionResolutionFailure(_, _) => {
57 "SUBGRAPH_ENDPOINT_EXPRESSION_RESOLUTION_FAILURE"
58 }
59 SubgraphExecutorError::EndpointExpressionWrongType(_) => {
60 "SUBGRAPH_ENDPOINT_EXPRESSION_WRONG_TYPE"
61 }
62 SubgraphExecutorError::StaticEndpointNotFound(_) => {
63 "SUBGRAPH_STATIC_ENDPOINT_NOT_FOUND"
64 }
65 SubgraphExecutorError::RequestBuildFailure(_, _) => "SUBGRAPH_REQUEST_BUILD_FAILURE",
66 SubgraphExecutorError::RequestFailure(_, _) => "SUBGRAPH_REQUEST_FAILURE",
67 SubgraphExecutorError::VariablesSerializationFailure(_, _) => {
68 "SUBGRAPH_VARIABLES_SERIALIZATION_FAILURE"
69 }
70 SubgraphExecutorError::TimeoutExpressionResolution(_, _) => {
71 "SUBGRAPH_TIMEOUT_EXPRESSION_RESOLUTION_FAILURE"
72 }
73 SubgraphExecutorError::RequestTimeout(_, _) => "SUBGRAPH_REQUEST_TIMEOUT",
74 SubgraphExecutorError::RequestTimeoutExpressionBuild(_, _) => {
75 "SUBGRAPH_TIMEOUT_EXPRESSION_BUILD_FAILURE"
76 }
77 }
78 }
79}