Skip to content

Commit

Permalink
Cleanup debugging code in hypixel module
Browse files Browse the repository at this point in the history
- trim unexpected whitespaces in the key
  • Loading branch information
moehreag committed Jan 13, 2025
1 parent 166a7fc commit de4384b
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/endpoints/hypixel.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::ClArgs;
use crate::{errors::ApiError, extractors::Authentication, ApiState};
use axum::http::{HeaderMap, HeaderName, HeaderValue};
use axum::response::IntoResponse;
use axum::{body::Body, extract::State, response::Response, Json};
use chrono::Utc;
Expand Down Expand Up @@ -151,20 +150,22 @@ async fn fetch_data(
let api_key = match &cl_args.hypixel.hypixel_api_key {
Some(api_key) => api_key,
None => match &cl_args.hypixel.hypixel_api_key_file {
Some(file) => &read_to_string(file).map_err(|e| ApiError::from(e).into_response())?,
Some(file) => &read_to_string(file)
.map(|s| s.trim().to_string())
.map_err(|e| ApiError::from(e).into_response())?,
None => unreachable!("clap should ensure that a url or url file is provided"),
},
};

let mut request_builder = client
.get(HYPIXEL_API_URL.to_string() + "/player?uuid=" + request_data_type.target_player.to_string().as_str());
let mut headers: HeaderMap = HeaderMap::new();
headers.insert(HeaderName::from_static("api-key"), HeaderValue::from_str(api_key).expect("Header value invalid"));
request_builder = request_builder.headers(headers);
let response = request_builder.send().await.map_err(|e| {
warn!("Failed to request player data from hypixel!");
ApiError::from(e).into_response()
})?;
let response = client
.get(HYPIXEL_API_URL.to_string() + "/player?uuid=" + request_data_type.target_player.to_string().as_str())
.header("api-key", api_key)
.send()
.await
.map_err(|e| {
warn!("Failed to request player data from hypixel!");
ApiError::from(e).into_response()
})?;

let limit = response
.headers()
Expand Down

0 comments on commit de4384b

Please sign in to comment.