Expand description
A small crate to manipulate base64 data.
§Features
- Maps all variants of
base64::DecodeErrorinto structuredcdumay_core::Errortypes. - 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
base64andcdumay_core. - Provides convenient macro for error conversion
§Usage
Using the Base64DecodeErrorConverter directly:
use base64::{engine::general_purpose, Engine as _};
use std::collections::BTreeMap;
use cdumay_core::{ErrorConverter, Error};
use cdumay_base64::Base64DecodeErrorConverter;
fn decode_base64(input: &str) -> cdumay_core::Result<Vec<u8>> {
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_decode_result! macro:
use base64::{engine::general_purpose, Engine as _};
use cdumay_core::{ErrorConverter, Error};
use std::collections::BTreeMap;
use cdumay_base64::convert_decode_result;
fn decode_base64(input: &str) -> cdumay_core::Result<Vec<u8>> {
let mut context = BTreeMap::new();
context.insert("input".to_string(), serde_value::Value::String(input.to_string()));
convert_decode_result!(general_purpose::STANDARD.decode(input), context, "Failed to decode base64")
}Macros§
- convert_
decode_ result - Macro to convert a
Result<T, base64::DecodeError>into acdumay_core::Result<T>
Structs§
- Base64
Decode Error Converter - A helper structure that converts
base64::DecodeErrorinto a structuredError. - Invalid
Byte Error - Error : InvalidByteError (Kind:
Base64Decode) - Invalid
Last Symbol Error - Error : InvalidLastSymbolError (Kind:
Base64Decode) - Invalid
Length Error - Error : InvalidLengthError (Kind:
Base64Decode) - Invalid
Padding Error - Error : InvalidPaddingError (Kind:
Base64Decode)
Constants§
- Base64
Decode - ErrorKind : Base64Decode (400) - Base64 decode error