Skip to content

Commit c6c2c38

Browse files
committed
fix: fail-open for autumn
1 parent 18b1b9c commit c6c2c38

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

apps/basket/src/lib/request-validation.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ import {
99
} from "../utils/validation";
1010
import { logBlockedTraffic } from "./blocked-traffic";
1111

12-
interface ValidationResult {
12+
type ValidationResult = {
1313
success: true;
1414
clientId: string;
1515
userAgent: string;
1616
ip: string;
1717
ownerId?: string;
18-
}
18+
};
1919

20-
interface ValidationError {
20+
type ValidationError = {
2121
error: { status: string; message: string };
22-
}
22+
};
2323

2424
/**
2525
* Validate incoming request for analytics events
@@ -72,23 +72,27 @@ export async function validateRequest(
7272
}
7373

7474
if (website.ownerId) {
75-
const { data } = await autumn.check({
76-
customer_id: website.ownerId,
77-
feature_id: "events",
78-
send_event: true,
79-
});
75+
try {
76+
const { data } = await autumn.check({
77+
customer_id: website.ownerId,
78+
feature_id: "events",
79+
send_event: true,
80+
});
8081

81-
if (!data?.allowed) {
82-
await logBlockedTraffic(
83-
request,
84-
body,
85-
query,
86-
"exceeded_event_limit",
87-
"Validation Error",
88-
undefined,
89-
clientId
90-
);
91-
return { error: { status: "error", message: "Exceeded event limit" } };
82+
if (data && !(data.allowed || data.overage_allowed)) {
83+
await logBlockedTraffic(
84+
request,
85+
body,
86+
query,
87+
"exceeded_event_limit",
88+
"Validation Error",
89+
undefined,
90+
clientId
91+
);
92+
return { error: { status: "error", message: "Exceeded event limit" } };
93+
}
94+
} catch (error) {
95+
console.error("Autumn check failed, allowing event through:", error);
9296
}
9397
}
9498

0 commit comments

Comments
 (0)