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
83
84
85
86
87
88
89
90
91
92
//! [](./LICENSE)
//! [](https://crates.io/crates/cdumay_error_base64)
//! [](https://docs.rs/cdumay_error_base64)
//! [](https://github.com/cdumay/cdumay_error_base64)
//!
//! A small utility crate for converting `base64::DecodeError` into structured, typed errors using the [`cdumay_error`](https://docs.rs/cdumay-error/) framework. This allows consistent, meaningful error reporting with custom codes, messages, and additional context.
//!
//! ## Features
//!
//! - Maps all variants of `base64::DecodeError` into structured `cdumay_error::Error` types.
//! - Provides unique error codes, HTTP status codes, and human-readable messages.
//! - Easily attach contextual metadata for better debugging.
//! - Simple integration into any Rust project using `base64` and `cdumay_error`.
//! - Provides a convenient `convert_result!` macro for error conversion
//!
//! ## Usage
//!
//! Using the `Base64DecodeErrorConverter` directly:
//! ```rust
//! use base64::{engine::general_purpose, Engine as _};
//! use cdumay_error::ErrorConverter;
//! use std::collections::BTreeMap;
//! use cdumay_error_base64::Base64DecodeErrorConverter;
//!
//! fn decode_base64(input: &str) -> Result<Vec<u8>, cdumay_error::Error> {
//! general_purpose::STANDARD.decode(input).map_err(|e| {
//! let mut context = BTreeMap::new();
//! context.insert("input".to_string(), serde_value::Value::String(input.to_string()));
//! Base64DecodeErrorConverter::convert(&e, "Failed to decode base64".to_string(), context)
//! })
//! }
//! ```
//! Using the `convert_result!` macro:
//! ```rust
//! use base64::{engine::general_purpose, Engine as _};
//! use cdumay_error::ErrorConverter;
//! use std::collections::BTreeMap;
//! use cdumay_error_base64::convert_result;
//!
//! fn decode_base64(input: &str) -> Result<Vec<u8>, cdumay_error::Error> {
//! convert_result!(general_purpose::STANDARD.decode(input), "Failed to decode base64")
//! }
//! ```
//!
use DecodeError;
use ;
use BTreeMap;
/// Defines a custom error kind for base64 decoding issues.
/// The error kind has a code, an HTTP status code, and a description.
define_kinds!
/// Associates the defined kind with a typed error.
///
/// This macro creates new error types based on the `Base64Decode`.
define_errors!
/// A helper structure that converts `base64::DecodeError` into a structured `Error`.
;