1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// SPDX-FileCopyrightText: 2025 RAprogramm <andrey.rozanov.vl@gmail.com>
//
// SPDX-License-Identifier: MIT
//! Wire-level error payload and HTTP integration.
//!
//! # Purpose
//!
//! [`ProblemJson`] serializes an RFC7807 payload designed for HTTP responses.
//! It augments the legacy [`ErrorResponse`] (still available for manual usage)
//! with:
//!
//! - canonical problem `type` URIs derived from [`AppCode`]
//! - a `title` computed from [`AppErrorKind`]
//! - the stable machine code plus optional gRPC mapping (`grpc.code`,
//! `grpc.value`)
//! - retry/authentication hints surfaced via the `Retry-After` and
//! `WWW-Authenticate` headers
//! - sanitized [`Metadata`] values when the error is not marked redactable
//!
//! When the message is tagged redactable (`AppError::redactable` or
//! `Context::redact(true)`), both `detail` and metadata are omitted to avoid
//! leaking sensitive information. The HTTP adapters (`axum`, `actix`) emit
//! `application/problem+json` bodies automatically via [`ProblemJson`].
//!
//! [`ErrorResponse`] remains available for backwards compatibility with
//! existing wire contracts and can be converted into [`ProblemJson`] via
//! [`ProblemJson::from_error_response`].
//!
//! # Example
//!
//! ```rust
//! use core::time::Duration;
//!
//! use masterror::{AppCode, ErrorResponse};
//!
//! let resp = ErrorResponse::new(404, AppCode::NotFound, "User not found")
//! .expect("status")
//! .with_retry_after_duration(Duration::from_secs(30));
//! ```
//!
//! With `serde_json` enabled:
//!
//! ```rust
//! # #[cfg(feature = "serde_json")]
//! # {
//! use masterror::{AppCode, ErrorResponse};
//! use serde_json::json;
//!
//! let resp = ErrorResponse::new(422, AppCode::Validation, "Invalid input")
//! .expect("status")
//! .with_details_json(json!({"field": "email", "error": "invalid"}));
//! # }
//! ```
//!
//! # Migration note
//!
//! Prior to version 0.3.0, `ErrorResponse::new` accepted only `(status,
//! message)`. This was replaced with `(status, code, message)` to expose a
//! stable machine-readable code. A temporary [`ErrorResponse::new_legacy`] is
//! provided as a deprecated shim.
pub
pub use ;
pub use ProblemJson;