Skip to content

Commit f4fc86f

Browse files
committed
fix kafkaBridge headers sent error
1 parent 8bdb5ad commit f4fc86f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

backend/bin/kafkaBridge.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,24 @@ app.post("/kafka-bridge/api/v0/event", async (req, res) => {
8181
}
8282
logger.info(`Producing to topic ${topic} payload ${JSON.stringify(payload)}`)
8383

84+
let error = false
85+
8486
try {
8587
producer.produce(topic, null, Buffer.from(JSON.stringify(payload)))
8688
flushProducer(1000).catch((err) => {
8789
logger.warn(new KafkaError("Flushing the producer failed", err))
88-
return res.status(500).json({ error: err.toString() }).send()
90+
error = true
91+
res.status(500).json({ error: err.toString() }).send()
8992
})
9093
} catch (e: any) {
9194
logger.error(new KafkaError("Producing to kafka failed", e))
95+
error = true
9296
return res.status(500).json({ error: e.toString() }).send()
9397
}
9498

95-
return res.json({ msg: "Thanks!" }).send()
99+
if (!error) {
100+
return res.json({ msg: "Thanks!" }).send()
101+
}
96102
})
97103

98104
app.get("/kafka-bridge/api/v0/healthz", (_, res) => {

0 commit comments

Comments
 (0)