pub trait ErrorExt {
// Required methods
fn to_json(&self, config: FormatConfig) -> Result<Value, Error>;
fn to_html(&self, config: FormatConfig) -> String;
fn to_graphql(&self, config: FormatConfig) -> Result<Value, Error>;
fn to_text(&self, config: FormatConfig) -> String;
fn to_jsonrpc(&self, config: FormatConfig) -> Result<Value, Error>;
fn http_status(&self) -> StatusCode;
fn http_headers(&self) -> Vec<(HeaderName, HeaderValue)>;
// Provided method
fn to_debug(&self) -> String
where Self: Debug { ... }
}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, FormatConfig};
fn handle_error(error: &dyn std::error::Error) {
let config = FormatConfig::default();
let graphql = error.to_graphql(config);
let json = error.to_json(config);
}Required Methods§
Sourcefn to_html(&self, config: FormatConfig) -> String
fn to_html(&self, config: FormatConfig) -> String
Render this error as HTML
Sourcefn to_graphql(&self, config: FormatConfig) -> Result<Value, Error>
fn to_graphql(&self, config: FormatConfig) -> Result<Value, Error>
Render this error as GraphQL JSON format
§Errors
Returns an error if any field fails to serialize to JSON
Sourcefn to_text(&self, config: FormatConfig) -> String
fn to_text(&self, config: FormatConfig) -> String
Render this error as plain text
Sourcefn to_jsonrpc(&self, config: FormatConfig) -> Result<Value, Error>
fn to_jsonrpc(&self, config: FormatConfig) -> 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
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".