chore: added errors to skip
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
import type { HonoEnv } from "@/honoUtils/HonoEnv.js";
|
||||
import { OrgService } from "@/internal/orgs/OrgService.js";
|
||||
import type { ExtendedRequest } from "@/utils/models/Request.js";
|
||||
import { handleWebhookErrorSkip } from "../../utils/routerUtils/webhookErrorSkip.js";
|
||||
import { handleStripeWebhookEvent } from "../stripe/handleStripeWebhookEvent.js";
|
||||
|
||||
export const connectWebhookRouter: Router = express.Router();
|
||||
@@ -117,7 +118,10 @@ export const handleConnectWebhook = async (c: Context<HonoEnv>) => {
|
||||
});
|
||||
return c.json({ message: "Webhook received" }, 200);
|
||||
} catch (error) {
|
||||
logger.error(`Stripe webhook, error: ${error}`, { error });
|
||||
const shouldSkip = handleWebhookErrorSkip({ error, logger });
|
||||
if (!shouldSkip) {
|
||||
logger.error(`Stripe webhook, error: ${error}`, { error });
|
||||
}
|
||||
return c.json({ message: "Webhook received, internal server error" }, 200);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -113,6 +113,14 @@ const STRIPE_RULES = [
|
||||
statusCode: 400,
|
||||
code: ErrCode.InvalidRequest,
|
||||
},
|
||||
{
|
||||
name: "Not a valid URL error",
|
||||
match: (err: Error) =>
|
||||
err instanceof Stripe.errors.StripeError &&
|
||||
err.message.includes("Not a valid URL"),
|
||||
statusCode: 400,
|
||||
code: ErrCode.InvalidRequest,
|
||||
},
|
||||
] as const;
|
||||
|
||||
/** Zod-specific error handling rules */
|
||||
@@ -124,6 +132,13 @@ const ZOD_RULES = [
|
||||
statusCode: 400,
|
||||
format: (err: ZodError) => formatZodError(err),
|
||||
},
|
||||
{
|
||||
name: "Zod error on /checkout (email validation)",
|
||||
match: (err: Error, c: Context<HonoEnv>) =>
|
||||
err instanceof ZodError && c.req.url.includes("/checkout"),
|
||||
statusCode: 400,
|
||||
format: (err: ZodError) => formatZodError(err),
|
||||
},
|
||||
] as const;
|
||||
|
||||
const createErrorResponse = ({
|
||||
|
||||
@@ -207,8 +207,6 @@ eventsRouter.post("", async (req: any, res: any) => {
|
||||
try {
|
||||
const body = req.body;
|
||||
|
||||
console.log("body", body);
|
||||
|
||||
if (!body.event_name && !body.feature_id) {
|
||||
throw new RecaseError({
|
||||
message: "event_name or feature_id is required",
|
||||
|
||||
@@ -145,6 +145,15 @@ export const handleExpressErrorSkip = ({
|
||||
code: ErrCode.InvalidRequest,
|
||||
});
|
||||
}
|
||||
|
||||
// Not a valid URL error
|
||||
if (error.message.includes("Not a valid URL")) {
|
||||
req.logger.warn(`Not a valid URL error, org: ${req.org?.slug}`);
|
||||
return res.status(400).json({
|
||||
message: error.message,
|
||||
code: ErrCode.InvalidRequest,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// No skip case matched
|
||||
|
||||
31
server/src/utils/routerUtils/webhookErrorSkip.ts
Normal file
31
server/src/utils/routerUtils/webhookErrorSkip.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { Logger } from "../../external/logtail/logtailUtils.js";
|
||||
|
||||
/**
|
||||
* Checks if a webhook error should be skipped (not logged).
|
||||
* Returns true if error should be skipped, false otherwise.
|
||||
*/
|
||||
export const handleWebhookErrorSkip = ({
|
||||
error,
|
||||
logger,
|
||||
}: {
|
||||
error: any;
|
||||
logger?: Logger;
|
||||
}): boolean => {
|
||||
const errorMessage = String(error);
|
||||
|
||||
// Skip "live mode key used" errors
|
||||
if (
|
||||
errorMessage.includes("but a live mode key was used to make this request.")
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Skip "Not a valid URL" errors
|
||||
if (errorMessage.includes("Not a valid URL")) {
|
||||
logger?.warn("Webhook error: Not a valid URL");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Don't skip this error
|
||||
return false;
|
||||
};
|
||||
Reference in New Issue
Block a user