oleksiyk / kafka

Apache Kafka 0.9 client for Node
MIT License
297 stars 85 forks source link

handling promises in no-kafka #202

Closed sharathbaddam closed 6 years ago

sharathbaddam commented 6 years ago

If i have any errors sending data to my kakfa broker using producer.send() where do i look for it ?

is it returned in .then(result) or in .catch(error) ?

oleksiyk commented 6 years ago

Kafka errors (like wrong/failed partition, etc) are returned in .then as a grand total result of publishing many messages to different topic/partitions pairs (some may succeed while other may fail). Severe errors (such as network errors, etc) are returned as rejected promise and should be processed .catch

sharathbaddam commented 6 years ago

Thanks for quick response, i was looking at documentation and found that result returned in then() looks something like this :- [ { topic: 'kafka-test-topic', partition: 0, offset: 353 } ] . If there is any error, other property like "error":"" is added in the object ? or i get completely different response ?

oleksiyk commented 6 years ago

The property error is always there. It is set to null when there is no error.

sharathbaddam commented 6 years ago

perfect!

But the typings file doesn't have error,

https://github.com/oleksiyk/kafka/blob/master/types/producer.d.ts#L182

Can we have to update the result interface in typings file to something like below ?

{ topic: string; partition: number; offset: number; error:NodeJS.ErrnoException }