Skip to main content

s3s_model/
error_codes.rs

1use std::collections::BTreeMap;
2
3use anyhow::Result;
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Serialize, Deserialize)]
7pub struct ErrorCode {
8    pub code: String,
9    pub description: String,
10    pub http_status_code: Option<u16>,
11}
12
13/// A map from category name to a list of error codes.
14pub type ErrorCodeMap = BTreeMap<String, Vec<ErrorCode>>;
15
16/// Load S3 error codes from a JSON file.
17///
18/// # Errors
19///
20/// Returns an error if the file cannot be read or parsed.
21pub fn load_json(path: &str) -> Result<ErrorCodeMap> {
22    let content = std::fs::read_to_string(path)?;
23    let map: ErrorCodeMap = serde_json::from_str(&content)?;
24    Ok(map)
25}