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§
Source§impl<S> FieldError<S>
impl<S> FieldError<S>
Sourcepub fn new<T: Display>(e: T, extensions: Value<S>) -> Self
pub fn new<T: Display>(e: T, extensions: Value<S>) -> Self
Construct a new FieldError
with additional data.
You can use the graphql_value!
macro for construction:
use juniper::{graphql_value, 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 "errors"
object in 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
, then no extra data will be included.
Sourcepub fn message(&self) -> &str
pub fn message(&self) -> &str
Returns "message"
field of this FieldError
.
Sourcepub fn extensions(&self) -> &Value<S>
pub fn extensions(&self) -> &Value<S>
Returns "extensions"
field of this FieldError
.
If there is no "extensions"
, then Value::Null
will be returned.
Sourcepub fn map_scalar_value<Into>(self) -> FieldError<Into>where
S: ScalarValue,
Into: ScalarValue,
pub fn map_scalar_value<Into>(self) -> FieldError<Into>where
S: ScalarValue,
Into: ScalarValue,
Maps the ScalarValue
type of this FieldError
into the specified
one.
Sourcepub fn map_message(self, f: impl FnOnce(String) -> String) -> Self
pub fn map_message(self, f: impl FnOnce(String) -> String) -> Self
Maps the FieldError::message
with the given function.
Trait Implementations§
Source§impl<S: Clone> Clone for FieldError<S>
impl<S: Clone> Clone for FieldError<S>
Source§fn clone(&self) -> FieldError<S>
fn clone(&self) -> FieldError<S>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<S: Debug> Debug for FieldError<S>
impl<S: Debug> Debug for FieldError<S>
Source§impl<T: Display, S> From<T> for FieldError<S>
impl<T: Display, S> From<T> for FieldError<S>
Source§impl<S1: ScalarValue, S2: ScalarValue> IntoFieldError<S2> for FieldError<S1>
impl<S1: ScalarValue, S2: ScalarValue> IntoFieldError<S2> for FieldError<S1>
Source§fn into_field_error(self) -> FieldError<S2>
fn into_field_error(self) -> FieldError<S2>
FieldError
.