pub enum ErrorTypeMode {
Url {
base_url: String,
},
Urn {
namespace: String,
},
}Expand description
How the RFC 9457 type field is rendered for ErrorCode.
RFC 9457 §3.1.1 requires type to be a URI reference and encourages using
resolvable URLs so consumers can look up documentation. This enum lets you
choose the format that fits your deployment.
Requires std or alloc (fields contain String).
§no_std note
This type is available with alloc alone, but the global accessors
error_type_mode and set_error_type_mode require the std feature
(RwLock + env-var access). In a no_std + alloc context, construct the
variant you need and call ErrorTypeMode::render directly.
§Configuration
Set the mode once at startup via set_error_type_mode, or let it
auto-resolve from environment variables (see error_type_mode).
§URL mode (recommended)
Produces {base_url}/{slug}, e.g.:
https://docs.myapp.com/errors/resource-not-found
Set via env: SHARED_TYPES_ERROR_TYPE_BASE_URL=https://docs.myapp.com/errors
§URN mode (fallback)
Produces urn:{namespace}:error:{slug}, e.g.:
urn:myapp:error:resource-not-found
Set via env: SHARED_TYPES_URN_NAMESPACE=myapp
§Examples
use api_bones::error::ErrorTypeMode;
let url_mode = ErrorTypeMode::Url { base_url: "https://docs.example.com/errors".into() };
assert_eq!(url_mode.render("not-found"), "https://docs.example.com/errors/not-found");
let urn_mode = ErrorTypeMode::Urn { namespace: "myapp".into() };
assert_eq!(urn_mode.render("not-found"), "urn:myapp:error:not-found");Variants§
Url
Generate a resolvable URL per RFC 9457 §3.1.1 (recommended).
Format: {base_url}/{slug} — trailing slash in base_url is trimmed automatically.
Urn
Generate a URN per RFC 9457 §3.1.1 + RFC 8141.
Format: urn:{namespace}:error:{slug}.
Implementations§
Source§impl ErrorTypeMode
impl ErrorTypeMode
Sourcepub fn render(&self, slug: &str) -> String
pub fn render(&self, slug: &str) -> String
Render the full type URI for a given error slug.
§Examples
use api_bones::error::ErrorTypeMode;
let mode = ErrorTypeMode::Url { base_url: "https://example.com/errors/".into() };
assert_eq!(mode.render("bad-request"), "https://example.com/errors/bad-request");
let mode = ErrorTypeMode::Urn { namespace: "acme".into() };
assert_eq!(mode.render("bad-request"), "urn:acme:error:bad-request");Trait Implementations§
Source§impl Clone for ErrorTypeMode
impl Clone for ErrorTypeMode
Source§fn clone(&self) -> ErrorTypeMode
fn clone(&self) -> ErrorTypeMode
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more