Skip to content

Commit

Permalink
Fix uncaught postgres error
Browse files Browse the repository at this point in the history
  • Loading branch information
roy-dydx committed Dec 9, 2024
1 parent fc5ff36 commit 4e18bf9
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions indexer/services/comlink/src/lib/compliance-and-geo-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -46,25 +49,35 @@ 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,
);
}
}

if (isRestrictedCountryHeaders(req.headers as CountryHeaders)) {
Expand Down

0 comments on commit 4e18bf9

Please sign in to comment.