Skip to content

Commit

Permalink
fix kafkaBridge headers sent error
Browse files Browse the repository at this point in the history
  • Loading branch information
mipyykko committed Mar 13, 2023
1 parent 8bdb5ad commit f4fc86f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions backend/bin/kafkaBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,24 @@ app.post("/kafka-bridge/api/v0/event", async (req, res) => {
}
logger.info(`Producing to topic ${topic} payload ${JSON.stringify(payload)}`)

let error = false

try {
producer.produce(topic, null, Buffer.from(JSON.stringify(payload)))
flushProducer(1000).catch((err) => {
logger.warn(new KafkaError("Flushing the producer failed", err))
return res.status(500).json({ error: err.toString() }).send()
error = true
res.status(500).json({ error: err.toString() }).send()
})
} catch (e: any) {
logger.error(new KafkaError("Producing to kafka failed", e))
error = true
return res.status(500).json({ error: e.toString() }).send()
}

return res.json({ msg: "Thanks!" }).send()
if (!error) {
return res.json({ msg: "Thanks!" }).send()
}
})

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

0 comments on commit f4fc86f

Please sign in to comment.