#ruul_webhooks
1 messages ยท Page 1 of 1 (latest)
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1247907160982290485
๐ Have more to share? Add details, code, screenshots, videos, etc. below.
port: env.ROOT_PORT,
url: env.ROOT_URL,
enableSubscriptions: true,
useJSONMiddleware: false,
middlewares: [
cors({ origin: "*" }),
["/stripe/webhooks", stripeWebhookMiddleware],
],
}),```
I'll provide some snippets
for clarity
I can't seem to open that Event ID... it may have a typo?
type: "*/*",
verify: (req: any, _res, buf, _encoding) => {
req.rawBody = buf;
},
});```
so some of the events are
returned as 502
to stripe
however I see signature errors
and api crashes lol
Idk how it'd send 502 to stripe because let me send 2 more snippets regarding this
it should've been 400
import { ContainerInstance, EventManager } from "@bluelibs/core";
import { StripeEvent } from "../events";
import { PaymentService } from "../services";
export const webhooksRoute: IRouteType = {
path: "/stripe/webhooks",
type: "post",
handler: async (
container: ContainerInstance,
req: express.Request,
res: express.Response
) => {
const paymentService = container.get(PaymentService);
const eventManager = container.get(EventManager);
const { event, error } = paymentService.constructEvent(req);
if (error) {
return res.status(400).send(`Error: ${error.toString()}`);
}
eventManager.emit(new StripeEvent({ event }));
return res.json({
received: true,
});
},
};
try {
return {
event: this.stripe.webhooks.constructEvent(
(req as any).rawBody, // even though we have defs, we get ts2339
req.headers["stripe-signature"],
env.STRIPE_WEBHOOKS_SECRET_KEY
) as Stripe.Event,
error: null,
};
} catch (error) {
this.loggerService.error(error.type);
return {
event: null,
error,
};
}
}```
I've tried to see some solutions to this on stackoverflow and they all had this kind of structure
the weird thing is
some of the webhook events actually succeed & they have received:true in response
and some crash with 502
and on logs I see something like
evt_1PO2oqJlGzvMDWmeTONdKCoT
Okay let's pause
ok
Okay so starting with that Event you just provided -- your server responded with a 502 with a response body of Bad Gateway. I assume that you don't have explicit code returning this response, correct?
yep
during the time our side crashed & last log was the unhandled rejection one I posted earlier
& I have no idea why it's unhandled because stripe package shows it as a sync method & it's wrapped inside try&catch
Yeah okay so mostly this seems like a server issue
Overall your code seems fine, especially since the retry was successful.
But that 502 response is coming from your server
So there is some issue before/after your actual webhook handler code
I'm thinking it's probably before, because if it's sometimes happening maybe it's corrupting the request & it's parsed incorrectly maybe resulting in this & indicating a false positive error for us
and another thing to note is
Ah yeah good point