Skip to content

Commit 3bb045e

Browse files
fix(cat-gateway): Return EventDBConnectionError to be handled by caller (#3680)
* fix(cat-gateway): Handle non-EventDB connection error * fix(cat-gateway): Return error to be handled by caller --------- Co-authored-by: Alex Pozhylenkov <[email protected]>
1 parent 8e51bf3 commit 3bb045e

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

catalyst-gateway/bin/src/db/event/signed_docs/full_signed_doc.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
//! `FullSignedDoc` struct implementation.
22
3+
use anyhow::Context;
4+
35
use super::SignedDocBody;
46
use crate::{
5-
db::event::EventDB,
7+
db::event::{EventDB, EventDBConnectionError},
68
jinja::{get_template, JinjaTemplateSource},
79
};
810

@@ -90,17 +92,16 @@ impl FullSignedDoc {
9092
match EventDB::modify(INSERT_SIGNED_DOCS, &self.postgres_db_fields()).await {
9193
// Able to insert, no conflict
9294
Ok(()) => Ok(true),
93-
Err(_) => {
95+
Err(e) if !e.is::<EventDBConnectionError>() => {
9496
// Attempt to retrieve the document now that we failed to insert
95-
match Self::retrieve(self.id(), Some(self.ver())).await {
96-
Ok(res_doc) => {
97-
anyhow::ensure!(&res_doc == self, StoreError);
98-
// Document already exists and matches, return false
99-
Ok(false)
100-
},
101-
Err(e) => Err(e),
102-
}
97+
let doc = Self::retrieve(self.id(), Some(self.ver()))
98+
.await
99+
.context("Cannot retrieve the document which has failed")?;
100+
anyhow::ensure!(&doc == self, StoreError);
101+
// Document already exists and matches, return false
102+
Ok(false)
103103
},
104+
Err(e) => Err(e),
104105
}
105106
}
106107

catalyst-gateway/bin/src/service/api/documents/put_document/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ async fn validate_against_original_doc(doc: &CatalystSignedDocument) -> anyhow::
174174
let original_doc = match FullSignedDoc::retrieve(&doc.doc_id()?.uuid(), None).await {
175175
Ok(doc) => doc,
176176
Err(e) if e.is::<error::NotFoundError>() => return Ok(true),
177-
Err(e) => anyhow::bail!("Database error: {e}"),
177+
Err(e) => return Err(e),
178178
};
179179

180180
let original_authors = original_doc

0 commit comments

Comments
 (0)