hyperlane_plugin_problem_details/struct.rs
1use super::*;
2
3/// Structured RFC 9457 Problem Details payload.
4#[derive(Clone, Data, Debug, Deserialize, Eq, PartialEq, Serialize)]
5pub struct ProblemDetails {
6 /// URI reference identifying the problem type (`"about:blank"` by default).
7 #[serde(rename = "type")]
8 pub(crate) problem_type: String,
9 /// Short, human-readable summary of the problem type.
10 pub(crate) title: String,
11 /// HTTP status code generated by the origin server.
12 #[get(type(copy))]
13 pub(crate) status: usize,
14 /// Optional human-readable explanation specific to this occurrence.
15 #[serde(skip_serializing_if = "Option::is_none")]
16 pub(crate) detail: Option<String>,
17 /// Optional URI reference identifying this specific occurrence (typically the request path).
18 #[serde(skip_serializing_if = "Option::is_none")]
19 pub(crate) instance: Option<String>,
20 /// Optional custom extension members flattened into the top-level JSON object.
21 #[serde(flatten, default, skip_serializing_if = "BTreeMap::is_empty")]
22 pub(crate) extensions: BTreeMap<String, Value>,
23}
24
25/// Configuration for [`ProblemDetailsPlugin`].
26#[derive(Clone, Data, Debug, Eq, PartialEq)]
27pub struct ProblemDetailsConfig {
28 /// Automatically convert empty or plain-text `4xx`/`5xx` responses into `application/problem+json`.
29 #[get(type(copy))]
30 pub(crate) auto_normalize: bool,
31 /// Include the incoming request path as the `instance` field during auto-normalization.
32 #[get(type(copy))]
33 pub(crate) include_instance: bool,
34 /// Optional base URI prefix for generated problem types (for example `"https://api.example.com/errors"`).
35 pub(crate) type_base_uri: Option<String>,
36 /// Redact raw `5xx` plain-text bodies instead of exposing internal details in `detail`.
37 #[get(type(copy))]
38 pub(crate) mask_server_error_details: bool,
39}
40
41/// Compiled RFC 9457 response normalizer backing [`ProblemDetailsHook`].
42#[derive(Clone, Debug)]
43pub struct ProblemDetailsPlugin {
44 /// Retained configuration.
45 pub(crate) config: ProblemDetailsConfig,
46 /// Trimmed base URI without trailing slash, if configured.
47 pub(crate) type_base_clean: Option<String>,
48}
49
50/// Opt-in response middleware normalizing `4xx`/`5xx` error responses into RFC 9457 Problem Details.
51#[derive(Clone, Copy, Debug, Default)]
52#[hyperlane::response_middleware(-62)]
53pub struct ProblemDetailsHook;