Skip to content

Commit

Permalink
Fix atproto fetch error (#22)
Browse files Browse the repository at this point in the history
* fix println! to error!

* fix error handling

* fix type
  • Loading branch information
takurinton authored May 22, 2024
1 parent 17457ca commit 4815b83
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
12 changes: 9 additions & 3 deletions src/handler/ready_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::env;
use crate::{commands, scheduler::processer::Processer};

use serenity::{client::Context, model::id::GuildId};
use tracing::info;
use tracing::{error, info};

pub async fn ready(ctx: Context) {
let guild_id = GuildId(889012300705591307);
Expand All @@ -30,11 +30,17 @@ pub async fn ready(ctx: Context) {
if mode == "production" {
// RSS feed を取得する
let rss_processor = crate::scheduler::rss::ProcesserStruct;
rss_processor.run(&ctx).await.unwrap();
match rss_processor.run(&ctx).await {
Ok(_) => info!("RSS feed fetched successfully."),
Err(why) => error!("Error fetching RSS feed: {:?}", why),
}

// 部分ツイートを取得する
let atproto_processor = crate::scheduler::atproto::ProcesserStruct;
atproto_processor.run(&ctx).await.unwrap();
match atproto_processor.run(&ctx).await {
Ok(_) => info!("部分ツイート fetched successfully."),
Err(why) => error!("Error fetching 部分ツイート: {:?}", why),
}
} else {
info!("RSS and 部分ツイート are not performed in development mode.");
}
Expand Down
27 changes: 14 additions & 13 deletions src/utils/fetch_atproto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::env;
use chrono::NaiveDateTime;
use serde::{Deserialize, Serialize};
use serenity::client::Context;
use tracing::error;

use crate::http::client::HttpClient;
use std::error::Error;
Expand Down Expand Up @@ -30,7 +31,7 @@ async fn create_session() -> Result<CreateSessionResponse, Box<dyn std::error::E
let identifier = match env::var("BSKY_IDENTIFIER") {
Ok(identifier) => identifier,
Err(why) => {
println!("Error: {:?}", why);
error!("Error: {:?}", why);
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::NotFound,
"BSKY_IDENTIFIER が取得できません。",
Expand All @@ -40,7 +41,7 @@ async fn create_session() -> Result<CreateSessionResponse, Box<dyn std::error::E
let password = match env::var("BSKY_PASS") {
Ok(password) => password,
Err(why) => {
println!("Error: {:?}", why);
error!("Error: {:?}", why);
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::NotFound,
"BSKY_PASS が取得できません。",
Expand All @@ -60,7 +61,7 @@ async fn create_session() -> Result<CreateSessionResponse, Box<dyn std::error::E
{
Ok(response) => response,
Err(why) => {
println!("Error: {:?}", why);
error!("Error: {:?}", why);
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::NotFound,
"API が取得できません。",
Expand All @@ -71,7 +72,7 @@ async fn create_session() -> Result<CreateSessionResponse, Box<dyn std::error::E
let json = match response.json::<CreateSessionResponse>().await {
Ok(json) => json,
Err(why) => {
println!("Error: {:?}", why);
error!("Error: {:?}", why);
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::NotFound,
"JSONのparseに失敗しました.",
Expand Down Expand Up @@ -103,7 +104,7 @@ pub struct Post {
// pub like_count: u32,
// pub indexed_at: String,
// pub viewer: Viewer,
pub labels: Vec<Label>,
// pub labels: Vec<Label>,
}

#[derive(Serialize, Deserialize, Debug)]
Expand All @@ -114,16 +115,16 @@ pub struct Author {
pub display_name: String,
pub avatar: String,
// pub viewer: Viewer,
pub labels: Vec<Label>,
// pub labels: Vec<Label>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Record {
#[serde(rename = "$type")]
pub record_type: String,
// #[serde(rename = "$type")]
// pub record_type: String,
#[warn(non_snake_case)]
pub createdAt: String,
pub langs: Vec<String>,
// pub langs: Vec<String>,
pub text: String,
}

Expand All @@ -133,8 +134,8 @@ pub struct Record {
// pub blocked_by: bool,
// }

#[derive(Serialize, Deserialize, Debug)]
pub struct Label {}
// #[derive(Serialize, Deserialize, Debug)]
// pub struct Label {}

async fn get_feed() -> Result<Body, Box<dyn std::error::Error>> {
let session = create_session().await?;
Expand All @@ -154,7 +155,7 @@ async fn get_feed() -> Result<Body, Box<dyn std::error::Error>> {
{
Ok(response) => response,
Err(why) => {
println!("Error: {:?}", why);
error!("Error: {:?}", why);
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::NotFound,
"API が取得できません。",
Expand All @@ -165,7 +166,7 @@ async fn get_feed() -> Result<Body, Box<dyn std::error::Error>> {
let json = match response.json::<Body>().await {
Ok(json) => json,
Err(why) => {
println!("Error: {:?}", why);
error!("Error: {:?}", why);
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::NotFound,
"JSONのparseに失敗しました.",
Expand Down

0 comments on commit 4815b83

Please sign in to comment.