Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add logs #146

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/endpoints/quests/focustree/engagement/discord_fw_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub async fn handler(
state.conf.variables.app_link, quest_id, task_id
);

println!("Authorization code: {}", authorization_code);

// Exchange the authorization code for an access token
let params = [
("client_id", &state.conf.discord.oauth2_clientid),
Expand All @@ -54,9 +56,16 @@ pub async fn handler(
),
("grant_type", &"authorization_code".to_string()),
];

println!("Params: {:?}", params);

let access_token = match exchange_authorization_code(params).await {
Ok(token) => token,
Ok(token) => {
println!("Access token: {}", token);
token
},
Err(e) => {
println!("Failed to exchange authorization code: {}", e);
return get_error_redirect(
error_redirect_uri,
format!("Failed to exchange authorization code: {}", e),
Expand Down Expand Up @@ -95,6 +104,7 @@ pub async fn handler(
}
};


for guild in response {
if guild.id == guild_id {
match state.upsert_completed_task(query.state, task_id).await {
Expand All @@ -105,7 +115,10 @@ pub async fn handler(
);
return success_redirect(redirect_uri);
}
Err(e) => return get_error_redirect(error_redirect_uri, format!("{}", e)),
Err(e) => {
println!("Guild Error: {}", e);
return get_error_redirect(error_redirect_uri, format!("{}", e))
},
}
}
}
Expand Down
29 changes: 26 additions & 3 deletions src/endpoints/quests/nostra/discord_fw_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ pub async fn handler(
state.conf.variables.app_link, quest_id, task_id
);

println!("Authorization code: {}", authorization_code);


// Exchange the authorization code for an access token
let params = [
("client_id", &state.conf.discord.oauth2_clientid),
Expand All @@ -54,9 +57,16 @@ pub async fn handler(
),
("grant_type", &"authorization_code".to_string()),
];

println!("Params: {:?}", params);

let access_token = match exchange_authorization_code(params).await {
Ok(token) => token,
Ok(token) => {
println!("Access token: {}", token);
token
},
Err(e) => {
println!("Failed to exchange authorization code: {}", e);
return get_error_redirect(
error_redirect_uri,
format!("Failed to exchange authorization code: {}", e),
Expand All @@ -71,12 +81,18 @@ pub async fn handler(
.header(AUTHORIZATION, format!("Bearer {}", access_token))
.send()
.await;
println!("Response result guild: {:?}", response_result);
let response: Vec<Guild> = match response_result {
Ok(response) => {
let json_result = response.json().await;
println!("JSON result guild: {:?}", json_result);
match json_result {
Ok(json) => json,
Ok(json) => {
println!("JSON: {:?}", json);
json
},
Err(e) => {
println!("Failed to get JSON response while fetching user info: {}", e);
return get_error_redirect(
error_redirect_uri,
format!(
Expand All @@ -88,6 +104,7 @@ pub async fn handler(
}
}
Err(e) => {
println!("Failed to send request to get user info response : {}", e);
return get_error_redirect(
error_redirect_uri,
format!("Failed to send request to get user info: {}", e),
Expand All @@ -96,6 +113,7 @@ pub async fn handler(
};

for guild in response {
println!("Guild: {:?}", guild);
if guild.id == guild_id {
match state.upsert_completed_task(query.state, task_id).await {
Ok(_) => {
Expand All @@ -105,7 +123,10 @@ pub async fn handler(
);
return success_redirect(redirect_uri);
}
Err(e) => return get_error_redirect(error_redirect_uri, format!("{}", e)),
Err(e) => {
println!("Guild Error: {}", e);
return get_error_redirect(error_redirect_uri, format!("{}", e))
},
}
}
}
Expand All @@ -125,6 +146,8 @@ async fn exchange_authorization_code(
.form(&params)
.send()
.await?;

println!("Response: {:?}", res);
let json: serde_json::Value = res.json().await?;
match json["access_token"].as_str() {
Some(s) => Ok(s.to_string()),
Expand Down