Return error, when Database insertion failed
This commit is contained in:
parent
b6abcd7c90
commit
5aeb937e6c
4 changed files with 14 additions and 3 deletions
|
@ -1,9 +1,9 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use axum::{body::Bytes, http::request};
|
||||
use axum::body::Bytes;
|
||||
use reqwest::{
|
||||
multipart::{Form, Part},
|
||||
Body, Client, Response, Url,
|
||||
Client, Response, Url,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
@ -69,7 +69,7 @@ impl IpfsClient {
|
|||
.post(self.url.join("/api/v0/pin/add")?)
|
||||
.query(&PinQuery::new(cid))
|
||||
.timeout(Duration::from_secs(60));
|
||||
let response = request.send().await?;
|
||||
request.send().await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ pub enum APIError {
|
|||
Unauthorized(String),
|
||||
#[error("{0}")]
|
||||
Forbidden(String),
|
||||
#[error("{0}")]
|
||||
Internal(String),
|
||||
#[error("IPFS error: {0}")]
|
||||
IPFS(#[from] IPFSError),
|
||||
}
|
||||
|
@ -53,6 +55,9 @@ impl IntoResponse for APIError {
|
|||
APIError::BadRequest(err) => ErrorResponse::new(StatusCode::BAD_REQUEST, Some(err)),
|
||||
APIError::Unauthorized(err) => ErrorResponse::new(StatusCode::UNAUTHORIZED, Some(err)),
|
||||
APIError::Forbidden(err) => ErrorResponse::new(StatusCode::FORBIDDEN, Some(err)),
|
||||
APIError::Internal(err) => {
|
||||
ErrorResponse::new(StatusCode::INTERNAL_SERVER_ERROR, Some(err))
|
||||
}
|
||||
APIError::IPFS(_) => ErrorResponse::new(StatusCode::INTERNAL_SERVER_ERROR, None),
|
||||
};
|
||||
let status = res.status.clone();
|
||||
|
|
|
@ -147,6 +147,11 @@ async fn upload(
|
|||
|
||||
for f in files {
|
||||
let res = cat.add_meme(&user, &f, &ip, &db_pool).await?;
|
||||
|
||||
if res != 1 {
|
||||
return Err(APIError::Internal("Database insertion error".to_string()));
|
||||
}
|
||||
|
||||
ipfs.pin(f.hash).await?;
|
||||
links.push(format!(
|
||||
"{}/{}/{}",
|
||||
|
|
1
src/v1/upload.rs
Normal file
1
src/v1/upload.rs
Normal file
|
@ -0,0 +1 @@
|
|||
|
Loading…
Reference in a new issue