From 5db5c847b26f788ba5c9a7108837cbecda963d5e Mon Sep 17 00:00:00 2001 From: Bartal Laearsson Date: Sun, 16 Aug 2026 23:05:29 +0100 Subject: [PATCH] phase 1 complete --- src/ingest.rs | 59 ++++++++++++++++++++++----------------------------- src/main.rs | 3 +++ src/types.rs | 9 +++++--- 3 files changed, 34 insertions(+), 37 deletions(-) diff --git a/src/ingest.rs b/src/ingest.rs index c778e5f..0238b4c 100644 --- a/src/ingest.rs +++ b/src/ingest.rs @@ -55,13 +55,9 @@ pub async fn fetch_metadata(client: &Client, url: &str) -> Result { .await?; if !resp.status().is_success() { + let status = resp.status().as_u16(); let body = resp.text().await.unwrap_or_default(); - return Err(IngestError::HttpError(reqwest::Error::from( - std::io::Error::new( - std::io::ErrorKind::Other, - format!("API returned error: {}", body), - ), - ))); + return Err(IngestError::ApiStatus { status, body }); } let meta: MetadataResponse = resp.json().await?; @@ -194,14 +190,9 @@ pub async fn fetch_data(client: &Client, url: &str, query: &Query) -> Result LookupMap { let mut maps = LookupMap::new(); maps.insert( - DIM_MONTH.to_string(), + "0".to_string(), // Tid / Month HashMap::from([ ("2015M01".to_string(), "Januar 2015".to_string()), ("2015M02".to_string(), "Februar 2015".to_string()), ]), ); maps.insert( - DIM_SPECIES.to_string(), + "1".to_string(), // Art / Species HashMap::from([ - ("148XXXXXXX00000".to_string(), "Sild".to_string()), - ("183XXXXXXX00000".to_string(), "Þorskur".to_string()), + ("Sild".to_string(), "Sild".to_string()), + ("Þorskur".to_string(), "Þorskur".to_string()), ]), ); maps.insert( - DIM_MEASURE.to_string(), + "7".to_string(), // Måleenhed / Measure HashMap::from([ - ("MASS".to_string(), "Nøgd".to_string()), - ("VALUE".to_string(), "Virði".to_string()), + ("MASS".to_string(), "Kilo".to_string()), + ("VALUE".to_string(), "Krónur".to_string()), ]), ); maps diff --git a/src/main.rs b/src/main.rs index ec562c9..0c6638b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,6 @@ +mod ingest; +mod types; + fn main() { println!("hagfish — not yet wired. Run tests with: cargo test"); } diff --git a/src/types.rs b/src/types.rs index fdd5a78..963a96d 100644 --- a/src/types.rs +++ b/src/types.rs @@ -251,17 +251,20 @@ pub enum IngestError { #[error("JSON parsing failed: {0}")] JsonError(#[from] serde_json::Error), + #[error("API returned status {status}: {body}")] + ApiStatus { status: u16, body: String }, + #[error("Missing dimension in response: {0}")] MissingDimension(String), - #[error("Invalid value: {0}")] + #[error("Invalid value code: {0}")] InvalidValueCode(String), #[error("API returned empty data set")] EmptyDataset, - #[error("Dimension '{0}' not found in metadata")] - DimensionNotFound(String), + #[error("Unicode decode error: {0}")] + UnicodeError(String), } // ---------------------------------------------------------------------------