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§
Sourcefn to_graphql(&self) -> Result<Value, Error>
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
Sourcefn to_jsonrpc(&self) -> Result<Value, Error>
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
Sourcefn http_status(&self) -> StatusCode
fn http_status(&self) -> StatusCode
Get the HTTP status code for this error
Sourcefn http_headers(&self) -> Vec<(HeaderName, HeaderValue)>
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".