Skip to content

Commit

Permalink
Fix uncaught postgres error (backport #2635) (#2641)
Browse files Browse the repository at this point in the history
Co-authored-by: roy-dydx <[email protected]>
  • Loading branch information
mergify[bot] and roy-dydx authored Dec 10, 2024
1 parent 87a43cd commit 2f5a70c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
49 changes: 31 additions & 18 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,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,
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion indexer/services/comlink/src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function handleControllerError(
);
}

function handleInternalServerError(
export function handleInternalServerError(
at: string,
message: string,
error: Error,
Expand Down

0 comments on commit 2f5a70c

Please sign in to comment.