Struct juniper::FieldError
source · pub struct FieldError<S = DefaultScalarValue> { /* private fields */ }
Expand description
Error type for errors that occur during field resolution
Field errors are represented by a human-readable error message and an
optional Value
structure containing additional information.
They can be converted to from any type that implements std::fmt::Display
,
which makes error chaining with the ?
operator a breeze:
fn get_string(data: Vec<u8>) -> Result<String, FieldError>
{
let s = String::from_utf8(data)?;
Ok(s)
}
Implementations
sourceimpl<S> FieldError<S>
impl<S> FieldError<S>
sourcepub fn new<T: Display>(e: T, extensions: Value<S>) -> FieldError<S>
pub fn new<T: Display>(e: T, extensions: Value<S>) -> FieldError<S>
Construct a new error with additional data
You can use the graphql_value!
macro to construct an error:
use juniper::FieldError;
FieldError::new(
"Could not open connection to the database",
graphql_value!({ "internal_error": "Connection refused" })
);
The extensions
parameter will be added to the "extensions"
field of the error
object in the JSON response:
{
"errors": [
"message": "Could not open connection to the database",
"locations": [{"line": 2, "column": 4}],
"extensions": {
"internal_error": "Connection refused"
}
]
}
If the argument is Value::null()
, no extra data will be included.
Trait Implementations
sourceimpl<S: Debug> Debug for FieldError<S>
impl<S: Debug> Debug for FieldError<S>
sourceimpl<T: Display, S> From<T> for FieldError<S>where
S: ScalarValue,
impl<T: Display, S> From<T> for FieldError<S>where
S: ScalarValue,
sourcefn from(e: T) -> FieldError<S>
fn from(e: T) -> FieldError<S>
Converts to this type from the input type.
sourceimpl<S: PartialEq> PartialEq<FieldError<S>> for FieldError<S>
impl<S: PartialEq> PartialEq<FieldError<S>> for FieldError<S>
sourcefn eq(&self, other: &FieldError<S>) -> bool
fn eq(&self, other: &FieldError<S>) -> bool
impl<S> IntoFieldError<S> for FieldError<S>
impl<S> StructuralPartialEq for FieldError<S>
Auto Trait Implementations
impl<S> RefUnwindSafe for FieldError<S>where
S: RefUnwindSafe,
impl<S> Send for FieldError<S>where
S: Send,
impl<S> Sync for FieldError<S>where
S: Sync,
impl<S> Unpin for FieldError<S>where
S: Unpin,
impl<S> UnwindSafe for FieldError<S>where
S: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more