@@ -249,41 +249,58 @@ async function calculateETag(
249
249
) : Promise < ETag | undefined > {
250
250
switch ( etagType ) {
251
251
case ETagType . chainTip :
252
- const chainTip = await db . getUnanchoredChainTip ( ) ;
253
- if ( ! chainTip . found ) {
254
- // This should never happen unless the API is serving requests before it has synced any blocks.
252
+ try {
253
+ const chainTip = await db . getUnanchoredChainTip ( ) ;
254
+ if ( ! chainTip . found ) {
255
+ // This should never happen unless the API is serving requests before it has synced any
256
+ // blocks.
257
+ return ;
258
+ }
259
+ return chainTip . result . microblockHash ?? chainTip . result . indexBlockHash ;
260
+ } catch ( error ) {
261
+ logger . error ( `Unable to calculate chain_tip ETag: ${ error } ` ) ;
255
262
return ;
256
263
}
257
- return chainTip . result . microblockHash ?? chainTip . result . indexBlockHash ;
258
264
259
265
case ETagType . mempool :
260
- const digest = await db . getMempoolTxDigest ( ) ;
261
- if ( ! digest . found ) {
262
- // This should never happen unless the API is serving requests before it has synced any blocks.
266
+ try {
267
+ const digest = await db . getMempoolTxDigest ( ) ;
268
+ if ( ! digest . found ) {
269
+ // This should never happen unless the API is serving requests before it has synced any
270
+ // blocks.
271
+ return ;
272
+ }
273
+ if ( digest . result . digest === null ) {
274
+ // A `null` mempool digest means the `bit_xor` postgres function is unavailable.
275
+ return ETAG_EMPTY ;
276
+ }
277
+ return digest . result . digest ;
278
+ } catch ( error ) {
279
+ logger . error ( `Unable to calculate mempool ETag: ${ error } ` ) ;
263
280
return ;
264
281
}
265
- if ( digest . result . digest === null ) {
266
- // A `null` mempool digest means the `bit_xor` postgres function is unavailable.
267
- return ETAG_EMPTY ;
268
- }
269
- return digest . result . digest ;
270
282
271
283
case ETagType . transaction :
272
- const { tx_id } = req . params ;
273
- const normalizedTxId = normalizeHashString ( tx_id ) ;
274
- if ( normalizedTxId === false ) {
275
- return ETAG_EMPTY ;
276
- }
277
- const status = await db . getTxStatus ( normalizedTxId ) ;
278
- if ( ! status . found ) {
279
- return ETAG_EMPTY ;
284
+ try {
285
+ const { tx_id } = req . params ;
286
+ const normalizedTxId = normalizeHashString ( tx_id ) ;
287
+ if ( normalizedTxId === false ) {
288
+ return ETAG_EMPTY ;
289
+ }
290
+ const status = await db . getTxStatus ( normalizedTxId ) ;
291
+ if ( ! status . found ) {
292
+ return ETAG_EMPTY ;
293
+ }
294
+ const elements : string [ ] = [
295
+ normalizedTxId ,
296
+ status . result . index_block_hash ?? '' ,
297
+ status . result . microblock_hash ?? '' ,
298
+ status . result . status . toString ( ) ,
299
+ ] ;
300
+ return elements . join ( ':' ) ;
301
+ } catch ( error ) {
302
+ logger . error ( `Unable to calculate transaction ETag: ${ error } ` ) ;
303
+ return ;
280
304
}
281
- const elements : string [ ] = [
282
- normalizedTxId ,
283
- status . result . index_block_hash ?? '' ,
284
- status . result . microblock_hash ?? '' ,
285
- status . result . status . toString ( ) ,
286
- ] ;
287
- return elements . join ( ':' ) ;
288
305
}
289
306
}
0 commit comments