mirror of
https://github.com/flibusta-apps/book_bot.git
synced 2025-12-06 15:35:35 +01:00
Fix 204 status code when download
This commit is contained in:
@@ -1,9 +1,25 @@
|
|||||||
|
use std::fmt;
|
||||||
|
use reqwest::StatusCode;
|
||||||
|
|
||||||
use crate::{bots::approved_bot::modules::download::DownloadData, config};
|
use crate::{bots::approved_bot::modules::download::DownloadData, config};
|
||||||
|
|
||||||
use self::types::{CachedMessage, DownloadFile};
|
use self::types::{CachedMessage, DownloadFile};
|
||||||
|
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
struct DownloadError {
|
||||||
|
status_code: StatusCode
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for DownloadError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "Status code is {0}", self.status_code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for DownloadError {}
|
||||||
|
|
||||||
pub async fn get_cached_message(
|
pub async fn get_cached_message(
|
||||||
download_data: &DownloadData,
|
download_data: &DownloadData,
|
||||||
) -> Result<CachedMessage, Box<dyn std::error::Error + Send + Sync>> {
|
) -> Result<CachedMessage, Box<dyn std::error::Error + Send + Sync>> {
|
||||||
@@ -83,6 +99,12 @@ pub async fn download_file(
|
|||||||
|
|
||||||
match response.error_for_status() {
|
match response.error_for_status() {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
|
if response.status() != StatusCode::OK {
|
||||||
|
return Err(Box::new(DownloadError {
|
||||||
|
status_code: response.status()
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
let headers = response.headers();
|
let headers = response.headers();
|
||||||
let filename = headers
|
let filename = headers
|
||||||
.get("content-disposition")
|
.get("content-disposition")
|
||||||
|
|||||||
Reference in New Issue
Block a user