Skip to content

Commit d9b2844

Browse files
committed
chore: fallback
1 parent 5c3b0fe commit d9b2844

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

platforms/blabsy-w3ds-auth-api/src/web3adapter/watchers/firestoreWatcher.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class FirestoreWatcher {
2323
constructor(
2424
private readonly collection:
2525
| CollectionReference<DocumentData>
26-
| CollectionGroup<DocumentData>
26+
| CollectionGroup<DocumentData>,
2727
) {}
2828

2929
async start(): Promise<void> {
@@ -42,7 +42,7 @@ export class FirestoreWatcher {
4242
async (snapshot) => {
4343
if (this.isProcessing) {
4444
console.log(
45-
"Still processing previous snapshot, skipping..."
45+
"Still processing previous snapshot, skipping...",
4646
);
4747
return;
4848
}
@@ -61,14 +61,14 @@ export class FirestoreWatcher {
6161
(error) => {
6262
console.error("Error in Firestore listener:", error);
6363
this.handleError(error);
64-
}
64+
},
6565
);
6666

6767
console.log(`Successfully started watcher for ${collectionPath}`);
6868
} catch (error) {
6969
console.error(
7070
`Failed to start watcher for ${collectionPath}:`,
71-
error
71+
error,
7272
);
7373
throw error;
7474
}
@@ -93,7 +93,7 @@ export class FirestoreWatcher {
9393
this.retryCount++;
9494
console.log(`Retrying (${this.retryCount}/${this.maxRetries})...`);
9595
await new Promise((resolve) =>
96-
setTimeout(resolve, this.retryDelay * this.retryCount)
96+
setTimeout(resolve, this.retryDelay * this.retryCount),
9797
);
9898
await this.start();
9999
} else {
@@ -109,7 +109,7 @@ export class FirestoreWatcher {
109109
? this.collection.path
110110
: "collection group";
111111
console.log(
112-
`Processing ${changes.length} changes in ${collectionPath}`
112+
`Processing ${changes.length} changes in ${collectionPath}`,
113113
);
114114

115115
for (const change of changes) {
@@ -122,7 +122,7 @@ export class FirestoreWatcher {
122122
case "modified":
123123
setTimeout(() => {
124124
console.log(
125-
`${collectionPath} - processing - ${doc.id}`
125+
`${collectionPath} - processing - ${doc.id}`,
126126
);
127127
if (adapter.lockedIds.includes(doc.id)) return;
128128
this.handleCreateOrUpdate(doc, data);
@@ -136,7 +136,7 @@ export class FirestoreWatcher {
136136
} catch (error) {
137137
console.error(
138138
`Error processing ${change.type} for document ${doc.id}:`,
139-
error
139+
error,
140140
);
141141
// Continue processing other changes even if one fails
142142
}
@@ -145,7 +145,7 @@ export class FirestoreWatcher {
145145

146146
private async handleCreateOrUpdate(
147147
doc: FirebaseFirestore.QueryDocumentSnapshot<DocumentData>,
148-
data: DocumentData
148+
data: DocumentData,
149149
): Promise<void> {
150150
const tableParts = doc.ref.path.split("/");
151151
// -2 cuz -1 gives last entry and we need second last which would
@@ -166,27 +166,31 @@ export class FirestoreWatcher {
166166
this.adapter.lockedIds.includes(doc.id)
167167
)
168168
return;
169-
const response = await axios.post(
170-
new URL(
171-
"/api/webhook",
172-
process.env.PUBLIC_PICTIQUE_BASE_URL
173-
).toString(),
174-
envelope,
175-
{
176-
headers: {
177-
"Content-Type": "application/json",
178-
"X-Webhook-Source": "blabsy-w3ds-auth-api",
169+
const response = await axios
170+
.post(
171+
new URL(
172+
"/api/webhook",
173+
process.env.PUBLIC_PICTIQUE_BASE_URL,
174+
).toString(),
175+
envelope,
176+
{
177+
headers: {
178+
"Content-Type": "application/json",
179+
"X-Webhook-Source": "blabsy-w3ds-auth-api",
180+
},
179181
},
180-
}
181-
);
182+
)
183+
.catch(() => null);
184+
if (!response)
185+
return console.error(`failed to sync ${envelope.id}`);
182186
console.log(
183187
`Successfully forwarded webhook for ${doc.id}:`,
184-
response.status
188+
response.status,
185189
);
186190
} catch (error) {
187191
console.error(
188192
`Failed to forward webhook for ${doc.id}:`,
189-
error
193+
error,
190194
);
191195
throw error; // Re-throw to trigger retry mechanism
192196
}

0 commit comments

Comments
 (0)