Skip to content

Commit

Permalink
api/ja4db: log update errors
Browse files Browse the repository at this point in the history
Currently the ja4db website is failing, but its hard to know that from
a simple "internal server" error returned to the client.
  • Loading branch information
jasonish committed Jul 10, 2024
1 parent 35ff3f8 commit 8881d6c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/server/api/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,33 @@

use std::sync::Arc;

use anyhow::Result;
use axum::{Extension, Json};
use tracing::info;
use tracing::error;

use crate::server::{main::SessionExtractor, ServerContext};

use super::ApiError;

pub(super) async fn update_ja4db(
context: Extension<Arc<ServerContext>>,
Extension(context): Extension<Arc<ServerContext>>,
_session: SessionExtractor,
) -> Result<Json<serde_json::Value>, ApiError> {
match do_update(context).await {
Ok(response) => Ok(response),
Err(err) => {
error!("Request to update JA4db failed: {err}");
Err(err.into())
}
}
}

async fn do_update(context: Arc<ServerContext>) -> Result<Json<serde_json::Value>> {
let mut conn = context.config_repo.pool.begin().await?;
info!("Updating JA4db");
let n = crate::commands::ja4db::updatedb(&mut conn).await?;
conn.commit().await?;
let response = json!({
"entries": n,
});
info!("JA4db successfully updated: entries={n}");
Ok(Json(response))
}

0 comments on commit 8881d6c

Please sign in to comment.