pub struct ProblemDetails {
pub type_uri: String,
pub title: String,
pub status: u16,
pub detail: Option<String>,
pub instance: Option<String>,
pub extensions: HashMap<String, Value>,
}Expand description
RFC 9457 Problem Details for HTTP APIs
A machine-readable format for specifying errors in HTTP API responses.
Per RFC 9457, all fields are optional. The type field defaults to “about:blank”
if not specified.
§Content-Type
Responses using this struct should set:
Content-Type: application/problem+json§Example
{
"type": "https://spikard.dev/errors/validation-error",
"title": "Request Validation Failed",
"status": 422,
"detail": "2 validation errors in request body",
"errors": [...]
}Fields§
§type_uri: StringA URI reference that identifies the problem type. Defaults to “about:blank” when absent. Should be a stable, human-readable identifier for the problem type.
title: StringA short, human-readable summary of the problem type. Should not change from occurrence to occurrence of the problem.
status: u16The HTTP status code generated by the origin server. This is advisory; the actual HTTP status code takes precedence.
detail: Option<String>A human-readable explanation specific to this occurrence of the problem.
instance: Option<String>A URI reference that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced.
extensions: HashMap<String, Value>Extension members - problem-type-specific data. For validation errors, this typically contains an “errors” array.
Implementations§
Source§impl ProblemDetails
impl ProblemDetails
Sourcepub const TYPE_VALIDATION_ERROR: &'static str = "https://spikard.dev/errors/validation-error"
pub const TYPE_VALIDATION_ERROR: &'static str = "https://spikard.dev/errors/validation-error"
Standard type URI for validation errors (422)
Sourcepub const TYPE_NOT_FOUND: &'static str = "https://spikard.dev/errors/not-found"
pub const TYPE_NOT_FOUND: &'static str = "https://spikard.dev/errors/not-found"
Standard type URI for not found errors (404)
Sourcepub const TYPE_METHOD_NOT_ALLOWED: &'static str = "https://spikard.dev/errors/method-not-allowed"
pub const TYPE_METHOD_NOT_ALLOWED: &'static str = "https://spikard.dev/errors/method-not-allowed"
Standard type URI for method not allowed (405)
Sourcepub const TYPE_INTERNAL_SERVER_ERROR: &'static str = "https://spikard.dev/errors/internal-server-error"
pub const TYPE_INTERNAL_SERVER_ERROR: &'static str = "https://spikard.dev/errors/internal-server-error"
Standard type URI for internal server error (500)
Sourcepub const TYPE_BAD_REQUEST: &'static str = "https://spikard.dev/errors/bad-request"
pub const TYPE_BAD_REQUEST: &'static str = "https://spikard.dev/errors/bad-request"
Standard type URI for bad request (400)
Sourcepub fn new(
type_uri: impl Into<String>,
title: impl Into<String>,
status: StatusCode,
) -> ProblemDetails
pub fn new( type_uri: impl Into<String>, title: impl Into<String>, status: StatusCode, ) -> ProblemDetails
Create a new ProblemDetails with required fields
Sourcepub fn with_detail(self, detail: impl Into<String>) -> ProblemDetails
pub fn with_detail(self, detail: impl Into<String>) -> ProblemDetails
Set the detail field
Sourcepub fn with_instance(self, instance: impl Into<String>) -> ProblemDetails
pub fn with_instance(self, instance: impl Into<String>) -> ProblemDetails
Set the instance field
Sourcepub fn with_extension(
self,
key: impl Into<String>,
value: Value,
) -> ProblemDetails
pub fn with_extension( self, key: impl Into<String>, value: Value, ) -> ProblemDetails
Add an extension field
Sourcepub fn with_extensions(self, extensions: Value) -> ProblemDetails
pub fn with_extensions(self, extensions: Value) -> ProblemDetails
Add all extensions from a JSON object
Sourcepub fn from_validation_error(error: &ValidationError) -> ProblemDetails
pub fn from_validation_error(error: &ValidationError) -> ProblemDetails
Create a validation error Problem Details from ValidationError
This converts the FastAPI-style validation errors to RFC 9457 format:
type: “https://spikard.dev/errors/validation-error”title: “Request Validation Failed”status: 422detail: Summary of error counterrors: Array of validation error details (as extension field)
Sourcepub fn not_found(detail: impl Into<String>) -> ProblemDetails
pub fn not_found(detail: impl Into<String>) -> ProblemDetails
Create a not found error
Sourcepub fn method_not_allowed(detail: impl Into<String>) -> ProblemDetails
pub fn method_not_allowed(detail: impl Into<String>) -> ProblemDetails
Create a method not allowed error
Sourcepub fn internal_server_error(detail: impl Into<String>) -> ProblemDetails
pub fn internal_server_error(detail: impl Into<String>) -> ProblemDetails
Create an internal server error
Sourcepub fn internal_server_error_debug(
detail: impl Into<String>,
exception: impl Into<String>,
traceback: impl Into<String>,
request_data: Value,
) -> ProblemDetails
pub fn internal_server_error_debug( detail: impl Into<String>, exception: impl Into<String>, traceback: impl Into<String>, request_data: Value, ) -> ProblemDetails
Create an internal server error with debug information
Includes exception details, traceback, and request data for debugging. Only use in development/debug mode.
Sourcepub fn bad_request(detail: impl Into<String>) -> ProblemDetails
pub fn bad_request(detail: impl Into<String>) -> ProblemDetails
Create a bad request error
Sourcepub fn status_code(&self) -> StatusCode
pub fn status_code(&self) -> StatusCode
Get the HTTP status code
Sourcepub fn to_json_pretty(&self) -> Result<String, Error>
pub fn to_json_pretty(&self) -> Result<String, Error>
Serialize to pretty JSON string
Trait Implementations§
Source§impl Clone for ProblemDetails
impl Clone for ProblemDetails
Source§fn clone(&self) -> ProblemDetails
fn clone(&self) -> ProblemDetails
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ProblemDetails
impl Debug for ProblemDetails
Source§impl Serialize for ProblemDetails
impl Serialize for ProblemDetails
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for ProblemDetails
impl RefUnwindSafe for ProblemDetails
impl Send for ProblemDetails
impl Sync for ProblemDetails
impl Unpin for ProblemDetails
impl UnwindSafe for ProblemDetails
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);