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

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

Formats the value using the given formatter. Read more
Converts to this type from the input type.
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Converts to this type from the input type.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.