Skip to main content

ErrorExt

Trait ErrorExt 

Source
pub trait ErrorExt {
    // Required methods
    fn to_json(&self) -> Result<Value, Error>;
    fn to_html(&self) -> String;
    fn to_graphql(&self) -> Result<Value, Error>;
    fn to_text(&self) -> String;
    fn to_debug(&self) -> String;
    fn to_jsonrpc(&self) -> Result<Value, Error>;
    fn http_status(&self) -> StatusCode;
    fn http_headers(&self) -> Vec<(HeaderName, HeaderValue)>;
}
Expand description

Extension trait for formatting any error type

This trait is implemented for dyn std::error::Error and uses the error registry to dynamically dispatch to the concrete error type’s apollo_errors::Error implementation.

§Example

use apollo_errors::ErrorExt;

fn handle_error(error: &dyn std::error::Error) {
    let graphql = error.to_graphql_ext();
    let json = error.to_json_ext();
}

Required Methods§

Source

fn to_json(&self) -> Result<Value, Error>

Render this error as JSON format

§Errors

Returns an error if any field fails to serialize to JSON

Source

fn to_html(&self) -> String

Render this error as HTML

Source

fn to_graphql(&self) -> Result<Value, Error>

Render this error as GraphQL JSON format

§Errors

Returns an error if any field fails to serialize to JSON

Source

fn to_text(&self) -> String

Render this error as plain text

Source

fn to_debug(&self) -> String

Render this error as debug format

Source

fn to_jsonrpc(&self) -> Result<Value, Error>

Render this error as JSON-RPC 2.0 error format

§Errors

Returns an error if any field fails to serialize to JSON

Source

fn http_status(&self) -> StatusCode

Get the HTTP status code for this error

Source

fn http_headers(&self) -> Vec<(HeaderName, HeaderValue)>

Get HTTP headers for this error

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<E: Error + 'static> ErrorExt for E

Blanket implementation for any concrete error type