Skip to content

Commit 230934e

Browse files
Release: develop -> master (#2867)
* fix: improve refund cronjob validation (#2866) * fix: allow BankTxReturn refund without userData The chargebackTx cronjob now handles two cases: 1. Entries WITH userData: check KYC/risk status as before 2. Entries WITHOUT userData: process without KYC/risk check This enables automatic refunds for unassigned deposits that have no associated user account. * fix: require creditorData for automatic refund processing Cronjob now only processes entries where chargebackCreditorData is set. This prevents unnecessary errors from validateRequiredCreditorFields. * fix: require creditorData for BuyCrypto bank refund processing Cronjob now only processes bank refunds where chargebackCreditorData is set. Checkout refunds don't need creditorData (handled by checkout provider). * fix: exclude 4xx client errors from Application Insights failures (#2865) * fix: exclude 4xx client errors from Application Insights failures Add TelemetryProcessor to mark 4xx responses as success=true. Only 5xx server errors should appear in the Failures dashboard. This reduces noise from expected client errors (400 Bad Request, 401 Unauthorized, 404 Not Found) in failure metrics and alerts. * fix: use correct type for responseCode (string, not number) Application Insights SDK types define responseCode as string. Use parseInt() for proper type conversion before comparison. * [NO-TASK] Minor improvements --------- Co-authored-by: TaprootFreak <142087526+TaprootFreak@users.noreply.github.com> Co-authored-by: David May <david.leo.may@gmail.com>
2 parents 3944479 + 5b3cf3c commit 230934e

4 files changed

Lines changed: 42 additions & 16 deletions

File tree

src/main.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ async function bootstrap() {
2626
if (process.env.APPINSIGHTS_INSTRUMENTATIONKEY) {
2727
AppInsights.setup().setAutoDependencyCorrelation(true).setAutoCollectConsole(true, true);
2828
AppInsights.defaultClient.context.tags[AppInsights.defaultClient.context.keys.cloudRole] = 'dfx-api';
29+
30+
// Don't mark 4xx client errors as failures - only 5xx are real server errors
31+
AppInsights.defaultClient.addTelemetryProcessor((envelope) => {
32+
const data = envelope.data as { baseType?: string; baseData?: { responseCode?: string; success?: boolean } };
33+
if (data.baseType === 'RequestData' && data.baseData?.responseCode) {
34+
const responseCode = parseInt(data.baseData.responseCode, 10);
35+
if (responseCode >= 400 && responseCode < 500) {
36+
data.baseData.success = true;
37+
}
38+
}
39+
return true;
40+
});
41+
2942
AppInsights.start();
3043
}
3144

src/subdomains/core/buy-crypto/process/services/buy-crypto-preparation.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,9 @@ export class BuyCryptoPreparationService {
464464
};
465465
const entities = await this.buyCryptoRepo.find({
466466
where: [
467-
{ ...baseRequest, chargebackIban: Not(IsNull()) },
467+
// Bank refund: requires creditorData for FiatOutput
468+
{ ...baseRequest, chargebackIban: Not(IsNull()), chargebackCreditorData: Not(IsNull()) },
469+
// Checkout refund: no creditorData needed
468470
{ ...baseRequest, checkoutTx: { id: Not(IsNull()) } },
469471
],
470472
relations: { checkoutTx: true, bankTx: true, cryptoInput: true, transaction: { userData: true } },

src/subdomains/generic/gs/gs.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export class GsService {
243243
}
244244

245245
// 10. Log query for audit trail
246-
this.logger.info(`Debug query by ${userIdentifier}: ${sql.substring(0, 500)}${sql.length > 500 ? '...' : ''}`);
246+
this.logger.verbose(`Debug query by ${userIdentifier}: ${sql.substring(0, 500)}${sql.length > 500 ? '...' : ''}`);
247247

248248
// 11. Execute query with result limit
249249
try {
@@ -255,7 +255,7 @@ export class GsService {
255255

256256
return result;
257257
} catch (e) {
258-
this.logger.warn(`Debug query by ${userIdentifier} failed: ${e.message}`);
258+
this.logger.info(`Debug query by ${userIdentifier} failed: ${e.message}`);
259259
throw new BadRequestException('Query execution failed');
260260
}
261261
}
@@ -285,7 +285,7 @@ export class GsService {
285285
kql += `\n| take ${template.defaultLimit}`;
286286

287287
// Log for audit
288-
this.logger.info(`Log query by ${userIdentifier}: template=${dto.template}, params=${JSON.stringify(dto)}`);
288+
this.logger.verbose(`Log query by ${userIdentifier}: template=${dto.template}, params=${JSON.stringify(dto)}`);
289289

290290
// Execute
291291
const timespan = `PT${dto.hours ?? 1}H`;
@@ -302,7 +302,7 @@ export class GsService {
302302
rows: response.tables[0].rows,
303303
};
304304
} catch (e) {
305-
this.logger.warn(`Log query by ${userIdentifier} failed: ${e.message}`);
305+
this.logger.info(`Log query by ${userIdentifier} failed: ${e.message}`);
306306
throw new BadRequestException('Query execution failed');
307307
}
308308
}

src/subdomains/supporting/bank-tx/bank-tx-return/bank-tx-return.service.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,30 @@ export class BankTxReturnService {
4242
}
4343

4444
async chargebackTx(): Promise<void> {
45+
const baseWhere = {
46+
chargebackAllowedDate: IsNull(),
47+
chargebackAllowedDateUser: Not(IsNull()),
48+
chargebackAmount: Not(IsNull()),
49+
chargebackIban: Not(IsNull()),
50+
chargebackCreditorData: Not(IsNull()),
51+
chargebackOutput: IsNull(),
52+
};
53+
4554
const entities = await this.bankTxReturnRepo.find({
46-
where: {
47-
chargebackAllowedDate: IsNull(),
48-
chargebackAllowedDateUser: Not(IsNull()),
49-
chargebackAmount: Not(IsNull()),
50-
chargebackIban: Not(IsNull()),
51-
chargebackOutput: IsNull(),
52-
userData: {
53-
kycStatus: In([KycStatus.NA, KycStatus.COMPLETED]),
54-
status: Not(UserDataStatus.BLOCKED),
55-
riskStatus: In([RiskStatus.NA, RiskStatus.RELEASED]),
55+
where: [
56+
{
57+
...baseWhere,
58+
userData: IsNull(),
5659
},
57-
},
60+
{
61+
...baseWhere,
62+
userData: {
63+
kycStatus: In([KycStatus.NA, KycStatus.COMPLETED]),
64+
status: Not(UserDataStatus.BLOCKED),
65+
riskStatus: In([RiskStatus.NA, RiskStatus.RELEASED]),
66+
},
67+
},
68+
],
5869
relations: { bankTx: true, userData: true },
5970
});
6071

0 commit comments

Comments
 (0)