Skip to content

Commit 735c792

Browse files
committed
chore: bump version to 1.27.5 and enhance error handling for token refresh failures
1 parent d5e43f6 commit 735c792

File tree

5 files changed

+57
-43
lines changed

5 files changed

+57
-43
lines changed

.talismanrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fileignoreconfig:
99
ignore_detectors:
1010
- filecontent
1111
- filename: package-lock.json
12-
checksum: 751efa34d2f832c7b99771568b5125d929dab095784b6e4ea659daaa612994c8
12+
checksum: 3dd53c4ecc763a41e74059c92fc97a0ad9f3da8877d6f5862d0d0108deef95d7
1313
- filename: .husky/pre-commit
1414
checksum: 52a664f536cf5d1be0bea19cb6031ca6e8107b45b6314fe7d47b7fad7d800632
1515
- filename: test/sanity-check/api/user-test.js

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [v1.27.5](https://github.com/contentstack/contentstack-management-javascript/tree/v1.27.5) (2026-02-16)
4+
- Fix
5+
- Skip token refresh on 401 when API returns error_code 161 (environment/permission) so the actual API error is returned instead of triggering refresh and a generic "Unable to refresh token" message
6+
- When token refresh fails after a 401, return the original API error (error_message, error_code) instead of the generic "Unable to refresh token" message
7+
38
## [v1.27.4](https://github.com/contentstack/contentstack-management-javascript/tree/v1.27.4) (2026-02-02)
49
- Fix
510
- Removed content-type header from the release delete method

lib/core/concurrency-queue.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,33 @@ export function ConcurrencyQueue ({ axios, config, plugins = [] }) {
400400
this.config.authtoken = token.authtoken
401401
}
402402
}).catch((error) => {
403+
const apiError = this._last401ApiError
404+
if (apiError) {
405+
this._last401ApiError = null
406+
}
403407
this.queue.forEach(queueItem => {
404-
queueItem.reject({
405-
errorCode: '401',
406-
errorMessage: (error instanceof Error) ? error.message : error,
407-
code: 'Unauthorized',
408-
message: 'Unable to refresh token',
409-
name: 'Token Error',
410-
config: queueItem.request,
411-
stack: (error instanceof Error) ? error.stack : null
412-
})
408+
if (apiError) {
409+
queueItem.reject({
410+
errorCode: apiError.error_code ?? '401',
411+
errorMessage: apiError.error_message || apiError.message || ((error instanceof Error) ? error.message : String(error)),
412+
code: 'Unauthorized',
413+
message: apiError.error_message || apiError.message || 'Unable to refresh token',
414+
name: 'Token Error',
415+
config: queueItem.request,
416+
stack: (error instanceof Error) ? error.stack : null,
417+
response: { status: 401, statusText: 'Unauthorized', data: apiError }
418+
})
419+
} else {
420+
queueItem.reject({
421+
errorCode: '401',
422+
errorMessage: (error instanceof Error) ? error.message : error,
423+
code: 'Unauthorized',
424+
message: 'Unable to refresh token',
425+
name: 'Token Error',
426+
config: queueItem.request,
427+
stack: (error instanceof Error) ? error.stack : null
428+
})
429+
}
413430
})
414431
this.queue = []
415432
this.running = []
@@ -511,6 +528,8 @@ export function ConcurrencyQueue ({ axios, config, plugins = [] }) {
511528
return Promise.reject(responseHandler(err))
512529
}
513530
this.running.shift()
531+
// Store original API error so we can return it if refresh fails (instead of generic message)
532+
this._last401ApiError = response.data
514533
// Cool down the running requests
515534
delay(wait, response.status === 401)
516535
error.config.retryCount = networkError

package-lock.json

Lines changed: 20 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/management",
3-
"version": "1.27.4",
3+
"version": "1.27.5",
44
"description": "The Content Management API is used to manage the content of your Contentstack account",
55
"main": "./dist/node/contentstack-management.js",
66
"browser": "./dist/web/contentstack-management.js",
@@ -54,13 +54,13 @@
5454
"dependencies": {
5555
"@contentstack/utils": "^1.6.3",
5656
"assert": "^2.1.0",
57-
"axios": "^1.12.2",
57+
"axios": "^1.13.5",
5858
"buffer": "^6.0.3",
5959
"form-data": "^4.0.5",
6060
"husky": "^9.1.7",
6161
"lodash": "^4.17.23",
6262
"otplib": "^12.0.1",
63-
"qs": "6.14.1",
63+
"qs": "^6.14.1",
6464
"stream-browserify": "^3.0.0"
6565
},
6666
"keywords": [

0 commit comments

Comments
 (0)