Skip to content

Commit b45fabb

Browse files
fix: prevent backend from crashing on network errors
1 parent c2ced0d commit b45fabb

23 files changed

Lines changed: 100 additions & 25 deletions

backend/src/services/user_stats/aither.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ impl Scraper for AitherScraper {
3636
.await
3737
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
3838

39-
let body = res.text().await.unwrap();
39+
let body = res
40+
.text()
41+
.await
42+
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
4043
let response = serde_json::from_str::<UnitedResponse>(&body).map_err(|e| {
4144
Error::CouldNotScrapeIndexer(format!("Your api key is probably invalid. {}", e))
4245
})?;

backend/src/services/user_stats/anime_bytes.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ impl Scraper for AnimeBytesScraper {
113113
.await
114114
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
115115

116-
let body = res.text().await.unwrap();
116+
let body = res
117+
.text()
118+
.await
119+
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
117120
let response = serde_json::from_str::<AnimeBytesResponse>(&body)
118121
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
119122

backend/src/services/user_stats/anthelion.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ impl Scraper for AnthelionScraper {
8383
.await
8484
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
8585

86-
let body = res.text().await.unwrap();
86+
let body = res
87+
.text()
88+
.await
89+
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
8790
let response = serde_json::from_str::<AnthelionResponse>(&body)
8891
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
8992
if response.response.is_none() {

backend/src/services/user_stats/blutopia.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ impl Scraper for BlutopiaScraper {
3636
.await
3737
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
3838

39-
let body = res.text().await.unwrap();
39+
let body = res
40+
.text()
41+
.await
42+
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
4043
let response = serde_json::from_str::<UnitedResponse>(&body).map_err(|e| {
4144
Error::CouldNotScrapeIndexer(format!("Your api key is probably invalid. {}", e))
4245
})?;

backend/src/services/user_stats/broadcasthenet.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ impl Scraper for BroadcasthenetScraper {
100100
.await
101101
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
102102

103-
let body = res.text().await.unwrap();
103+
let body = res
104+
.text()
105+
.await
106+
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
104107
let response = serde_json::from_str::<BroadcasthenetResponse>(&body)
105108
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
106109
if response.result.is_none() {

backend/src/services/user_stats/darkpeers.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ impl Scraper for DarkPeersScraper {
3636
.await
3737
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
3838

39-
let body = res.text().await.unwrap();
39+
let body = res
40+
.text()
41+
.await
42+
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
4043
let response = serde_json::from_str::<UnitedResponse>(&body).map_err(|e| {
4144
Error::CouldNotScrapeIndexer(format!("Your api key is probably invalid. {}", e))
4245
})?;

backend/src/services/user_stats/fear_no_peer.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ impl Scraper for FearNoPeerScraper {
3636
.await
3737
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
3838

39-
let body = res.text().await.unwrap();
39+
let body = res
40+
.text()
41+
.await
42+
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
4043
let response = serde_json::from_str::<UnitedResponse>(&body).map_err(|e| {
4144
Error::CouldNotScrapeIndexer(format!("Your api key is probably invalid. {}", e))
4245
})?;

backend/src/services/user_stats/gazelle_games.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ impl Scraper for GazelleGamesScraper {
151151
.await
152152
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
153153

154-
let body = res.text().await.unwrap();
154+
let body = res
155+
.text()
156+
.await
157+
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
155158
let response = serde_json::from_str::<GazelleGamesResponse>(&body)
156159
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
157160

backend/src/services/user_stats/homiehelpdesk.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ impl Scraper for HomieHelpDeskScraper {
3636
.await
3737
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
3838

39-
let body = res.text().await.unwrap();
39+
let body = res
40+
.text()
41+
.await
42+
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
4043
let response = serde_json::from_str::<UnitedResponse>(&body).map_err(|e| {
4144
Error::CouldNotScrapeIndexer(format!("Your api key is probably invalid. {}", e))
4245
})?;

backend/src/services/user_stats/ita_torrents.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ impl Scraper for ItaTorrentsScraper {
3636
.await
3737
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
3838

39-
let body = res.text().await.unwrap();
39+
let body = res
40+
.text()
41+
.await
42+
.map_err(|e| Error::CouldNotScrapeIndexer(e.to_string()))?;
4043
let response = serde_json::from_str::<UnitedResponse>(&body).map_err(|e| {
4144
Error::CouldNotScrapeIndexer(format!("Your api key is probably invalid. {}", e))
4245
})?;

0 commit comments

Comments
 (0)