Skip to content

Commit d9958cf

Browse files
committed
Reconcile createTopics type and behaviour
1 parent 788a972 commit d9958cf

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/kafkajs/_admin.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class Admin {
207207
/**
208208
* Create topics with the given configuration.
209209
* @param {{ validateOnly?: boolean, waitForLeaders?: boolean, timeout?: number, topics: import("../../types/kafkajs").ITopicConfig[] }} options
210-
* @returns {Promise<void>} Resolves when the topics are created, rejects on error.
210+
* @returns {Promise<boolean>} Resolves true when the topics are created, false if topic exists already, rejects on error.
211211
*/
212212
async createTopics(options) {
213213
if (this.#state !== AdminState.CONNECTED) {
@@ -229,9 +229,13 @@ class Admin {
229229
.map(topicConfig => new Promise((resolve, reject) => {
230230
this.#internalClient.createTopic(topicConfig, options.timeout ?? 5000, (err) => {
231231
if (err) {
232+
if (err.code === error.ErrorCodes.ERR_TOPIC_ALREADY_EXISTS) {
233+
resolve(false);
234+
return;
235+
}
232236
reject(createKafkaJsErrorFromLibRdKafkaError(err));
233237
} else {
234-
resolve();
238+
resolve(true);
235239
}
236240
});
237241
}));

0 commit comments

Comments
 (0)