Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
---
changelog:
- date: 2026-01-13
version: v10.2.6
changes:
- type: improvement
text: "Prevent retry when response is having http status code 404."
- date: 2025-12-16
version: v10.2.5
changes:
Expand Down Expand Up @@ -1379,7 +1384,7 @@ supported-platforms:
- 'Ubuntu 14.04 and up'
- 'Windows 7 and up'
version: 'Pubnub Javascript for Node'
version: '10.2.5'
version: '10.2.6'
sdks:
- full-name: PubNub Javascript SDK
short-name: Javascript
Expand All @@ -1395,7 +1400,7 @@ sdks:
- distribution-type: source
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/archive/refs/tags/v10.2.5.zip
location: https://github.com/pubnub/javascript/archive/refs/tags/v10.2.6.zip
requires:
- name: 'agentkeepalive'
min-version: '3.5.2'
Expand Down Expand Up @@ -2066,7 +2071,7 @@ sdks:
- distribution-type: library
distribution-repository: GitHub release
package-name: pubnub.js
location: https://github.com/pubnub/javascript/releases/download/v10.2.5/pubnub.10.2.5.js
location: https://github.com/pubnub/javascript/releases/download/v10.2.6/pubnub.10.2.6.js
requires:
- name: 'agentkeepalive'
min-version: '3.5.2'
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v10.2.6
January 13 2026

#### Modified
- Prevent retry when response is having http status code 404.

## v10.2.5
December 16 2025

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2
npm install pubnub
```
* or download one of our builds from our CDN:
* https://cdn.pubnub.com/sdk/javascript/pubnub.10.2.5.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.10.2.5.min.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.10.2.6.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.10.2.6.min.js

2. Configure your keys:

Expand Down
6 changes: 4 additions & 2 deletions dist/web/pubnub.js
Original file line number Diff line number Diff line change
Expand Up @@ -3118,6 +3118,8 @@
data !== null && data !== void 0 ? data : (data = response.body);
if (status === 402)
message = 'Not available for used key set. Contact support@pubnub.com';
else if (status === 404)
message = 'Resource not found';
else if (status === 400) {
category = StatusCategory$1.PNBadRequestCategory;
message = 'Bad request';
Expand Down Expand Up @@ -5436,7 +5438,7 @@
return base.PubNubFile;
},
get version() {
return '10.2.5';
return '10.2.6';
},
getVersion() {
return this.version;
Expand Down Expand Up @@ -5790,7 +5792,7 @@
activeCancellation = attemptCancellation;
const responseHandler = (res, error) => {
const retriableError = error ? error.category !== StatusCategory$1.PNCancelledCategory : true;
const retriableStatusCode = !res || res.status >= 400;
const retriableStatusCode = (!res || res.status >= 400) && (error === null || error === void 0 ? void 0 : error.statusCode) !== 404;
let delay = -1;
if (retriableError &&
retriableStatusCode &&
Expand Down
4 changes: 2 additions & 2 deletions dist/web/pubnub.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/core/components/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const makeConfiguration = (base, setupCryptoModule) => {
return base.PubNubFile;
},
get version() {
return '10.2.5';
return '10.2.6';
},
getVersion() {
return this.version;
Expand Down
2 changes: 2 additions & 0 deletions lib/errors/pubnub-api-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class PubNubAPIError extends Error {
data !== null && data !== void 0 ? data : (data = response.body);
if (status === 402)
message = 'Not available for used key set. Contact support@pubnub.com';
else if (status === 404)
message = 'Resource not found';
else if (status === 400) {
category = categories_1.default.PNBadRequestCategory;
message = 'Bad request';
Expand Down
2 changes: 1 addition & 1 deletion lib/transport/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class PubNubMiddleware {
activeCancellation = attemptCancellation;
const responseHandler = (res, error) => {
const retriableError = error ? error.category !== categories_1.default.PNCancelledCategory : true;
const retriableStatusCode = !res || res.status >= 400;
const retriableStatusCode = (!res || res.status >= 400) && (error === null || error === void 0 ? void 0 : error.statusCode) !== 404;
let delay = -1;
if (retriableError &&
retriableStatusCode &&
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pubnub",
"version": "10.2.5",
"version": "10.2.6",
"author": "PubNub <support@pubnub.com>",
"description": "Publish & Subscribe Real-time Messaging with PubNub",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export const makeConfiguration = (
return base.PubNubFile;
},
get version(): string {
return '10.2.5';
return '10.2.6';
},
getVersion(): string {
return this.version;
Expand Down
1 change: 1 addition & 0 deletions src/errors/pubnub-api-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export class PubNubAPIError extends Error {
data ??= response.body;

if (status === 402) message = 'Not available for used key set. Contact support@pubnub.com';
else if (status === 404) message = 'Resource not found';
else if (status === 400) {
category = StatusCategory.PNBadRequestCategory;
message = 'Bad request';
Expand Down
2 changes: 1 addition & 1 deletion src/transport/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class PubNubMiddleware implements Transport {

const responseHandler = (res?: TransportResponse, error?: PubNubAPIError) => {
const retriableError = error ? error.category !== StatusCategory.PNCancelledCategory : true;
const retriableStatusCode = !res || res.status >= 400;
const retriableStatusCode = (!res || res.status >= 400) && error?.statusCode !== 404;
let delay = -1;

if (
Expand Down
59 changes: 59 additions & 0 deletions test/integration/endpoints/objects/channel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import nock from 'nock';
import { asResponse, allChannels, channel1 } from './fixtures.js';
import PubNub from '../../../../src/node/index';
import utils from '../../../utils';
import { RetryPolicy } from '../../../../src/core/components/retry-policy.js';

describe('objects channel', () => {
const PUBLISH_KEY = 'myPublishKey';
Expand Down Expand Up @@ -727,4 +728,62 @@ describe('objects channel', () => {
expect(lastResult.data).to.have.length.lessThan(10);
});
});
describe('retry policy', () => {
it('should not retry on 404 Not Found error with linear retry policy', async () => {
const channelName = 'non-existent-channel';

// Set up nock mock before creating PubNub instance
const scope = utils
.createNock()
.get(`/v2/objects/${SUBSCRIBE_KEY}/channels/${channelName}`)
.times(1)
.query(true)
.reply(404, {
status: 404,
error: {
message: 'Requested object was not found.',
source: 'objects',
},
});

// Create a new PubNub instance with linear retry policy
const pubnubWithRetry = new PubNub({
subscribeKey: SUBSCRIBE_KEY,
publishKey: PUBLISH_KEY,
uuid: UUID,
// @ts-expect-error Force override default value.
useRequestId: false,
authKey: AUTH_KEY,
retryConfiguration: RetryPolicy.LinearRetryPolicy({
delay: 2,
maximumRetry: 2,
}),
});

let caughtError: any;
try {
await pubnubWithRetry.objects.getChannelMetadata({ channel: channelName });
} catch (error) {
caughtError = error;
}

// Verify that an error was thrown
expect(caughtError).to.exist;

// Verify the error status code is 404
expect(caughtError).to.have.property('status');
expect(caughtError.status.statusCode).to.equal(404);

// Verify the error message
expect(caughtError.status.errorData).to.exist;
expect(caughtError.status.errorData.error).to.exist;
expect(caughtError.status.errorData.error.message).to.equal('Requested object was not found.');
expect(caughtError.status.errorData.error.source).to.equal('objects');

// Verify the scope was called exactly once (no retries on 404
expect(scope.isDone()).to.be.true;

pubnubWithRetry.destroy(true);
});
});
});
60 changes: 60 additions & 0 deletions test/integration/endpoints/objects/uuid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import nock from 'nock';

import { asResponse, allUsers, user1 } from './fixtures';
import PubNub from '../../../../src/node/index';
import { RetryPolicy } from '../../../../src/core/components/retry-policy.js';
import utils from '../../../utils';

describe('objects UUID', () => {
Expand Down Expand Up @@ -322,4 +323,63 @@ describe('objects UUID', () => {
});
});
});

describe('retry policy', () => {
it('should not retry on 404 Not Found error with linear retry policy', async () => {
const nonExistentUUID = 'non-existent-uuid';

// Set up nock mock before creating PubNub instance
const scope = utils
.createNock()
.get(`/v2/objects/${SUBSCRIBE_KEY}/uuids/${nonExistentUUID}`)
.times(1)
.query(true)
.reply(404, {
status: 404,
error: {
message: 'Requested object was not found.',
source: 'objects',
},
});

// Create a new PubNub instance with linear retry policy
const pubnubWithRetry = new PubNub({
subscribeKey: SUBSCRIBE_KEY,
publishKey: PUBLISH_KEY,
uuid: UUID,
// @ts-expect-error Force override default value.
useRequestId: false,
authKey: AUTH_KEY,
retryConfiguration: RetryPolicy.LinearRetryPolicy({
delay: 2,
maximumRetry: 2,
}),
});

let caughtError: any;
try {
await pubnubWithRetry.objects.getUUIDMetadata({ uuid: nonExistentUUID });
} catch (error) {
caughtError = error;
}

// Verify that an error was thrown
expect(caughtError).to.exist;

// Verify the error status code is 404
expect(caughtError).to.have.property('status');
expect(caughtError.status.statusCode).to.equal(404);

// Verify the error message
expect(caughtError.status.errorData).to.exist;
expect(caughtError.status.errorData.error).to.exist;
expect(caughtError.status.errorData.error.message).to.equal('Requested object was not found.');
expect(caughtError.status.errorData.error.source).to.equal('objects');

// Verify the scope was called exactly once (no retries on 404)
expect(scope.isDone()).to.be.true;

pubnubWithRetry.destroy(true);
});
});
});
Loading