Skip to content

Commit 7da57ec

Browse files
authored
Merge pull request #4 from contentstack/development
Request failure retry count
2 parents c0d867d + 7bf1c5c commit 7da57ec

9 files changed

+1499
-1493
lines changed

.npmignore

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@ typings
1515
webpack/
1616
tsconfig.json
1717
.jsdoc.json
18-
jsdocs/
18+
jsdocs/
19+
docdash-template/
20+
.env
21+
.babelrc
22+
.babel-preset.js
23+
.eslintrc.js

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# Changelog
2+
3+
## [v1.1.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.1.2) (2021-01-07)
4+
- Bug Fix
5+
- Retry count on multiple request failuer
6+
## [v1.1.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.1.1) (2020-10-23)
7+
- Bug Fix
8+
- Stack initialization issue
29
## [v1.1.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.1.0) (2020-10-23)
310
- Bug Fix
411
- Owner of organization can access stack function

lib/contentstackClient.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default function contentstackClient ({ http }) {
8282
* import * as contentstack from '@contentstack/management'
8383
* const client = contentstack.client()
8484
*
85-
* client.stack({ api_key: 'api_key', management_token: 'management_token' }).fetch()
85+
* client.stack({ api_key: 'api_key', management_token: 'management_token' }).contentType('content_type_uid').fetch()
8686
* .then((stack) => console.log(stack))
8787
*
8888
*/

lib/core/contentstack-retry.js

+16-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
export default function contentstckRetry (axios, defaultOptions, retryLimit = 5, retryDelay = 300) {
33
var networkError = 0
44
axios.interceptors.request.use(function (config) {
5+
config.retryCount = config.retryCount || 0
56
if (config.headers.authorization && config.headers.authorization !== undefined) {
67
delete config.headers.authtoken
78
}
@@ -13,15 +14,23 @@ export default function contentstckRetry (axios, defaultOptions, retryLimit = 5,
1314
}, function (error) {
1415
var wait = retryDelay
1516
let retryErrorType = null
16-
if (!defaultOptions.retryOnError) {
17-
return Promise.reject(error)
18-
}
19-
2017
var response = error.response
18+
networkError = error.config.retryCount
2119
if (!response) {
22-
retryErrorType = `Server connection`
20+
if (error.code === 'ECONNABORTED') {
21+
error.response = {
22+
...error.response,
23+
status: 408,
24+
statusText: `timeout of ${defaultOptions.timeout}ms exceeded`
25+
}
26+
}else {
27+
return Promise.reject(error)
28+
}
29+
}
30+
if (!defaultOptions.retryOnError) {
2331
return Promise.reject(error)
2432
}
33+
2534
if (defaultOptions.retryCondition && defaultOptions.retryCondition(error)) {
2635
retryErrorType = `Error with status: ${error.response.status}`
2736
networkError++
@@ -46,6 +55,8 @@ export default function contentstckRetry (axios, defaultOptions, retryLimit = 5,
4655
networkError = 0
4756
}
4857

58+
error.config.retryCount = networkError
59+
4960
if (retryErrorType && error.config !== undefined) {
5061
var config = error.config
5162
defaultOptions.logHandler('warning', `${retryErrorType} error occurred. Waiting for ${wait} ms before retrying...`)

lib/entity.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export const fetch = (http, type) => {
186186
response.data[type]['content_type'] = response.data['content_type']
187187
response.data[type]['schema'] = response.data['schema']
188188
}
189-
return Object.assign(this, cloneDeep(response.data[type]))
189+
return new this.constructor(http, parseData(response, this.stackHeaders))
190190
} else {
191191
throw error(response)
192192
}

lib/organization/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function Organization (http, data) {
7575
* import * as contentstack from '@contentstack/management'
7676
* const client = contentstack.client()
7777
*
78-
* client.stack({ api_key: 'api_key'}).transferOwnership('emailId')
78+
* client.organization('organization_uid').transferOwnership('emailId')
7979
* .then((response) => console.log(response.notice))
8080
*
8181
*/

lib/stack/index.js

-7
Original file line numberDiff line numberDiff line change
@@ -579,13 +579,6 @@ export function Stack (http, data) {
579579
* import * as contentstack from '@contentstack/management'
580580
* const client = contentstack.client()
581581
*
582-
* client.organization('org_uid').stack().create({name: 'My New Stack'})
583-
* .then((stack) => console.log(stack))
584-
*
585-
* @example
586-
* import * as contentstack from '@contentstack/management'
587-
* const client = contentstack.client()
588-
*
589582
* client.stack().create({name: 'My New Stack'}, { organization_uid: 'org_uid' })
590583
* .then((stack) => console.log(stack))
591584
*/

0 commit comments

Comments
 (0)