mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-03 17:08:13 +00:00
error messages on failure to download (#1349)
This commit is contained in:
1 parent
6fe0909879
commit
5770534fc3
8 files changed
+66
-13
No files matched your search
+1
-1
@@ -239,7 +239,7 @@ async fn upload_to_kinovi(
|
||||
.await
|
||||
.map_err(|err| {
|
||||
warn!("Error downloading media file from CDN: {:?}", err);
|
||||
AdvancedCommonWebError::from_anyhow_error(err)
|
||||
AdvancedCommonWebError::from_error(err)
|
||||
})?
|
||||
.to_vec();
|
||||
|
||||
|
||||
+1
-1
@@ -683,7 +683,7 @@ async fn upload_to_seedance2pro(
|
||||
.await
|
||||
.map_err(|err| {
|
||||
warn!("Error downloading media file from CDN: {:?}", err);
|
||||
AdvancedCommonWebError::from_anyhow_error(err)
|
||||
AdvancedCommonWebError::from_error(err)
|
||||
})?
|
||||
.to_vec();
|
||||
|
||||
|
||||
+2
-2
@@ -35,7 +35,7 @@ pub async fn process_image_payload(
|
||||
.await
|
||||
.map_err(|err| {
|
||||
warn!("Failed to download image from {}: {:?}", image_url, err);
|
||||
AdvancedCommonWebError::from_anyhow_error(err)
|
||||
AdvancedCommonWebError::from_error(err)
|
||||
})?;
|
||||
|
||||
if file_bytes.len() <= 10 {
|
||||
@@ -48,7 +48,7 @@ pub async fn process_image_payload(
|
||||
.await
|
||||
.map_err(|err| {
|
||||
warn!("Failed to download image on retry from {}: {:?}", image_url, err);
|
||||
AdvancedCommonWebError::from_anyhow_error(err)
|
||||
AdvancedCommonWebError::from_error(err)
|
||||
})?;
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -35,7 +35,9 @@ pub async fn process_images_payload(
|
||||
maybe_batch_token = Some(BatchGenerationToken::generate());
|
||||
}
|
||||
|
||||
for image in images_data {
|
||||
for (i, image) in images_data.iter().enumerate() {
|
||||
info!("Uploading image {} of {}: {:?}", i + 1, images_data.len(), image.url);
|
||||
|
||||
let media_token = upload_image(job, server_state, image, maybe_batch_token.as_ref()).await?;
|
||||
|
||||
if maybe_media_token.is_none() {
|
||||
@@ -83,6 +85,8 @@ async fn upload_image(
|
||||
})?;
|
||||
}
|
||||
|
||||
info!("Resolving metadata...");
|
||||
|
||||
// Resolve mime type: magic bytes first, fal content_type as fallback.
|
||||
let metadata = resolve_file_metadata(&file_bytes, image.content_type.as_deref())
|
||||
.ok_or_else(|| {
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ pub async fn process_model_glb_payload(
|
||||
.await
|
||||
.map_err(|err| {
|
||||
warn!("Failed to download mesh from {}: {:?}", mesh_url, err);
|
||||
AdvancedCommonWebError::from_anyhow_error(err)
|
||||
AdvancedCommonWebError::from_error(err)
|
||||
})?;
|
||||
|
||||
if file_bytes.len() <= 10 {
|
||||
|
||||
+2
-2
@@ -33,7 +33,7 @@ pub async fn process_model_mesh_payload(
|
||||
.await
|
||||
.map_err(|err| {
|
||||
warn!("Failed to download mesh from {}: {:?}", mesh_url, err);
|
||||
AdvancedCommonWebError::from_anyhow_error(err)
|
||||
AdvancedCommonWebError::from_error(err)
|
||||
})?;
|
||||
|
||||
if file_bytes.len() <= 10 {
|
||||
@@ -46,7 +46,7 @@ pub async fn process_model_mesh_payload(
|
||||
.await
|
||||
.map_err(|err| {
|
||||
warn!("Failed to download mesh on retry from {}: {:?}", mesh_url, err);
|
||||
AdvancedCommonWebError::from_anyhow_error(err)
|
||||
AdvancedCommonWebError::from_error(err)
|
||||
})?;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -37,7 +37,7 @@ pub async fn process_video_payload(
|
||||
.await
|
||||
.map_err(|err| {
|
||||
warn!("Failed to download video from {}: {:?}", video_url, err);
|
||||
AdvancedCommonWebError::from_anyhow_error(err)
|
||||
AdvancedCommonWebError::from_error(err)
|
||||
})?;
|
||||
|
||||
if file_bytes.len() <= 10 {
|
||||
@@ -50,7 +50,7 @@ pub async fn process_video_payload(
|
||||
.await
|
||||
.map_err(|err| {
|
||||
warn!("Failed to download video on retry from {}: {:?}", video_url, err);
|
||||
AdvancedCommonWebError::from_anyhow_error(err)
|
||||
AdvancedCommonWebError::from_error(err)
|
||||
})?;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,25 @@
|
||||
use bytes::Bytes;
|
||||
use errors::AnyhowResult;
|
||||
use wreq::Client;
|
||||
use log::warn;
|
||||
use std::error::Error;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use wreq::{Client, StatusCode};
|
||||
|
||||
const USER_AGENT: &str = "storyteller-web/1.0";
|
||||
|
||||
// TODO(bt, 2025-06-03): Don't load the entire file into memory!
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum DownloadFileToBytesError {
|
||||
WreqError(wreq::Error),
|
||||
BadResponseError {
|
||||
status_code: StatusCode,
|
||||
body: Bytes,
|
||||
url: String,
|
||||
}
|
||||
}
|
||||
|
||||
/// Downloads a (binary) file to memory. Good for images, etc. Not great for large files.
|
||||
pub async fn http_download_url_to_bytes(url: &str) -> AnyhowResult<Bytes> {
|
||||
pub async fn http_download_url_to_bytes(url: &str) -> Result<Bytes, DownloadFileToBytesError> {
|
||||
let client = Client::builder()
|
||||
.gzip(true)
|
||||
.build()?;
|
||||
@@ -18,7 +30,44 @@ pub async fn http_download_url_to_bytes(url: &str) -> AnyhowResult<Bytes> {
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
let status = response.status();
|
||||
let bytes = response.bytes().await?;
|
||||
|
||||
if !status.is_success() {
|
||||
warn!("Error downloading URL (status={}): {:?}", status.as_u16(), url);
|
||||
|
||||
return Err(DownloadFileToBytesError::BadResponseError {
|
||||
status_code: status,
|
||||
body: bytes,
|
||||
url: url.to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
impl Error for DownloadFileToBytesError {
|
||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
||||
match self {
|
||||
DownloadFileToBytesError::WreqError(e) => Some(e),
|
||||
DownloadFileToBytesError::BadResponseError { .. } => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for DownloadFileToBytesError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
DownloadFileToBytesError::WreqError(e) => write!(f, "Wreq error: {}", e),
|
||||
DownloadFileToBytesError::BadResponseError { status_code, body, url } => {
|
||||
write!(f, "Bad response (status={}) fetching {} : {:?}", status_code.as_u16(), url, body)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<wreq::Error> for DownloadFileToBytesError {
|
||||
fn from(e: wreq::Error) -> Self {
|
||||
DownloadFileToBytesError::WreqError(e)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user