diff --git a/indexer/services/comlink/src/lib/compliance-and-geo-check.ts b/indexer/services/comlink/src/lib/compliance-and-geo-check.ts index fe0f64400b..94733d15bf 100644 --- a/indexer/services/comlink/src/lib/compliance-and-geo-check.ts +++ b/indexer/services/comlink/src/lib/compliance-and-geo-check.ts @@ -14,7 +14,10 @@ import express from 'express'; import { matchedData } from 'express-validator'; import { AddressRequest, BlockedCode } from '../types'; -import { create4xxResponse } from './helpers'; +import { + create4xxResponse, + handleInternalServerError, +} from './helpers'; import { getIpAddr, isIndexerIp } from './utils'; /** @@ -46,24 +49,34 @@ export async function complianceAndGeoCheck( } if (address !== undefined) { - const updatedStatus: ComplianceStatusFromDatabase[] = await ComplianceStatusTable.findAll( - { address: [address] }, - [], - { readReplica: true }, - ); - if (updatedStatus.length > 0) { - if (updatedStatus[0].status === ComplianceStatus.CLOSE_ONLY || - updatedStatus[0].status === ComplianceStatus.FIRST_STRIKE_CLOSE_ONLY - ) { - return next(); - } else if (updatedStatus[0].status === ComplianceStatus.BLOCKED) { - return create4xxResponse( - res, - INDEXER_COMPLIANCE_BLOCKED_PAYLOAD, - 403, - { code: BlockedCode.COMPLIANCE_BLOCKED }, - ); + try { + const updatedStatus: ComplianceStatusFromDatabase[] = await ComplianceStatusTable.findAll( + { address: [address] }, + [], + { readReplica: true }, + ); + if (updatedStatus.length > 0) { + if (updatedStatus[0].status === ComplianceStatus.CLOSE_ONLY || + updatedStatus[0].status === ComplianceStatus.FIRST_STRIKE_CLOSE_ONLY + ) { + return next(); + } else if (updatedStatus[0].status === ComplianceStatus.BLOCKED) { + return create4xxResponse( + res, + INDEXER_COMPLIANCE_BLOCKED_PAYLOAD, + 403, + { code: BlockedCode.COMPLIANCE_BLOCKED }, + ); + } } + } catch (error) { + return handleInternalServerError( + 'complianceAndGeoCheck', + 'complianceAndGeoCheck error', + error, + req, + res, + ); } } diff --git a/indexer/services/comlink/src/lib/helpers.ts b/indexer/services/comlink/src/lib/helpers.ts index 16d27bf624..b072ca4b0d 100644 --- a/indexer/services/comlink/src/lib/helpers.ts +++ b/indexer/services/comlink/src/lib/helpers.ts @@ -82,7 +82,7 @@ export function handleControllerError( ); } -function handleInternalServerError( +export function handleInternalServerError( at: string, message: string, error: Error,