diff --git a/src/admin/__tests__/fetchTopicMetadata.spec.js b/src/admin/__tests__/fetchTopicMetadata.spec.js index 484561c9a..18978fceb 100644 --- a/src/admin/__tests__/fetchTopicMetadata.spec.js +++ b/src/admin/__tests__/fetchTopicMetadata.spec.js @@ -101,7 +101,10 @@ describe('Admin', () => { admin.fetchTopicMetadata({ topics: [existingTopicName, newTopicName], }) - ).rejects.toHaveProperty('message', 'This server does not host this topic-partition') + ).rejects.toHaveProperty( + 'message', + `This server does not host this topic-partition [${newTopicName}]` + ) }) }) }) diff --git a/src/errors.js b/src/errors.js index 15ec77c83..0e1cd421c 100644 --- a/src/errors.js +++ b/src/errors.js @@ -38,9 +38,14 @@ class KafkaJSOffsetOutOfRange extends KafkaJSProtocolError { } } +/** + * Wraps 'UNKNOWN_TOPIC_OR_PARTITION' (code=3) but is only + * used in cases where it is clearly the topic that is unknown + * (e.g. a `metadata` request has no partition parameter) + */ class KafkaJSUnknownTopic extends KafkaJSProtocolError { constructor(e, { topic }) { - super(e) + super(e, { retriable: false }) this.topic = topic this.name = 'KafkaJSUnknownTopic' this.message = `${this.message} [${this.topic}]` @@ -52,9 +57,10 @@ class KafkaJSTopicAuthorizationFailed extends KafkaJSProtocolError { super(e, { retriable: false }) this.topic = topic this.name = 'KafkaJSTopicAuthorizationFailed' - this.message = `${this.message} [${this.topic})]` + this.message = `${this.message} [${this.topic}]` } } + class KafkaJSMemberIdRequired extends KafkaJSProtocolError { constructor(e, { memberId }) { super(e) diff --git a/src/protocol/error.js b/src/protocol/error.js index b212abaa8..fa1a42e1f 100644 --- a/src/protocol/error.js +++ b/src/protocol/error.js @@ -24,7 +24,7 @@ const errorCodes = [ { type: 'UNKNOWN_TOPIC_OR_PARTITION', code: 3, - retriable: false, + retriable: true, message: 'This server does not host this topic-partition', }, { diff --git a/src/protocol/requests/metadata/v0/response.spec.js b/src/protocol/requests/metadata/v0/response.spec.js index 0d7d9d42e..5321b07b0 100644 --- a/src/protocol/requests/metadata/v0/response.spec.js +++ b/src/protocol/requests/metadata/v0/response.spec.js @@ -71,7 +71,7 @@ describe('Protocol > Requests > Metadata > v0', () => { test('when topicErrorCode is UNKNOWN_TOPIC_OR_PARTITION', async () => { decoded.topicMetadata[0].topicErrorCode = 3 await expect(response.parse(decoded)).rejects.toMatchObject({ - message: createErrorFromCode(3).message, + message: createErrorFromCode(3).message + ' [test-topic-1]', retriable: false, type: 'UNKNOWN_TOPIC_OR_PARTITION', code: 3, @@ -83,7 +83,7 @@ describe('Protocol > Requests > Metadata > v0', () => { test('when topicErrorCode is TOPIC_AUTHORIZATION_FAILED', async () => { decoded.topicMetadata[0].topicErrorCode = 29 await expect(response.parse(decoded)).rejects.toMatchObject({ - message: createErrorFromCode(29).message, + message: createErrorFromCode(29).message + ' [test-topic-1]', retriable: false, type: 'TOPIC_AUTHORIZATION_FAILED', code: 29, diff --git a/types/index.d.ts b/types/index.d.ts index 05531eec9..cbbcae53f 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1290,6 +1290,7 @@ export interface KafkaJSOffsetOutOfRangeMetadata { export interface KafkaJSUnknownTopicMetadata { topic: string } + export interface KafkaJSTopicAuthorizationFailedMetadata { topic: string } diff --git a/types/tests.ts b/types/tests.ts index 22b6e329f..b26b72fd8 100644 --- a/types/tests.ts +++ b/types/tests.ts @@ -342,4 +342,4 @@ new KafkaJSServerDoesNotSupportApiKey( ) new KafkaJSUnknownTopic('This server does not host this topic-partition', { topic: 'my_topic' }) -new KafkaJSTopicAuthorizationFailed('Not authorized to access topics: [Topic authorization failed]', { topic: 'my_topic' }) \ No newline at end of file +new KafkaJSTopicAuthorizationFailed('Not authorized to access topics: [Topic authorization failed]', { topic: 'my_topic' })