409 on duplicate
This commit is contained in:
@@ -1151,9 +1151,10 @@ pub async fn update_document(
|
||||
match update_result.execute(&mut conn) {
|
||||
Ok(_) => {}
|
||||
Err(diesel::result::Error::DatabaseError(DatabaseErrorKind::UniqueViolation, _)) => {
|
||||
return Err(AppError::bad_request(
|
||||
return Err(AppError::conflict(
|
||||
"another document in this folder already uses that filename",
|
||||
));
|
||||
)
|
||||
.with_code("duplicate_filename"));
|
||||
}
|
||||
Err(err) => return Err(AppError::from(err)),
|
||||
}
|
||||
@@ -1822,7 +1823,7 @@ async fn process_upload(
|
||||
|
||||
let (document, version) = {
|
||||
let mut conn = state.db_for_tenant(tenant_id)?;
|
||||
conn.transaction(|conn| {
|
||||
let transaction_result = conn.transaction(|conn| {
|
||||
let new_document = NewDocument {
|
||||
id: doc_id,
|
||||
filename: stored_filename.clone(),
|
||||
@@ -1859,7 +1860,18 @@ async fn process_upload(
|
||||
let version: DocumentVersion = document_versions::table.find(version_id).first(conn)?;
|
||||
|
||||
Ok::<_, diesel::result::Error>((document, version))
|
||||
})?
|
||||
});
|
||||
|
||||
match transaction_result {
|
||||
Ok(result) => result,
|
||||
Err(diesel::result::Error::DatabaseError(DatabaseErrorKind::UniqueViolation, _)) => {
|
||||
return Err(AppError::conflict(
|
||||
"another document in this folder already uses that filename",
|
||||
)
|
||||
.with_code("duplicate_filename"))
|
||||
}
|
||||
Err(err) => return Err(AppError::from(err)),
|
||||
}
|
||||
};
|
||||
|
||||
let detail = {
|
||||
|
||||
Reference in New Issue
Block a user