Struct async_graphql::ServerError
source · pub struct ServerError {
pub message: String,
pub source: Option<Arc<dyn Any + Send + Sync>>,
pub locations: Vec<Pos>,
pub path: Vec<PathSegment>,
pub extensions: Option<ErrorExtensionValues>,
}
Expand description
An error in a GraphQL server.
Fields§
§message: String
An explanatory message of the error.
source: Option<Arc<dyn Any + Send + Sync>>
The source of the error.
locations: Vec<Pos>
Where the error occurred.
path: Vec<PathSegment>
If the error occurred in a resolver, the path to the error.
extensions: Option<ErrorExtensionValues>
Extensions to the error.
Implementations§
source§impl ServerError
impl ServerError
sourcepub fn new(message: impl Into<String>, pos: Option<Pos>) -> Self
pub fn new(message: impl Into<String>, pos: Option<Pos>) -> Self
Create a new server error with the message.
sourcepub fn source<T: Any + Send + Sync>(&self) -> Option<&T>
pub fn source<T: Any + Send + Sync>(&self) -> Option<&T>
Get the source of the error.
Examples
use std::io::ErrorKind;
use async_graphql::*;
struct Query;
#[Object]
impl Query {
async fn value(&self) -> Result<i32> {
Err(Error::new_with_source(std::io::Error::new(
ErrorKind::Other,
"my error",
)))
}
}
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
let err = schema
.execute("{ value }")
.await
.into_result()
.unwrap_err()
.remove(0);
assert!(err.source::<std::io::Error>().is_some());
Trait Implementations§
source§impl Clone for ServerError
impl Clone for ServerError
source§fn clone(&self) -> ServerError
fn clone(&self) -> ServerError
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for ServerError
impl Debug for ServerError
source§impl<'de> Deserialize<'de> for ServerError
impl<'de> Deserialize<'de> for ServerError
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Display for ServerError
impl Display for ServerError
source§impl From<Error> for ServerError
impl From<Error> for ServerError
source§impl From<ServerError> for Vec<ServerError>
impl From<ServerError> for Vec<ServerError>
source§fn from(single: ServerError) -> Self
fn from(single: ServerError) -> Self
Converts to this type from the input type.