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.
Auto Trait Implementations§
impl Freeze for ServerError
impl !RefUnwindSafe for ServerError
impl Send for ServerError
impl Sync for ServerError
impl Unpin for ServerError
impl !UnwindSafe for ServerError
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)