Skip to content

Commit

Permalink
do not retry on get token & await remove sync info
Browse files Browse the repository at this point in the history
  • Loading branch information
cnwangjie committed Aug 30, 2018
1 parent f6fce71 commit a81b92e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 37 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"vue-router": "^3.0.1",
"vuedraggable": "^2.16.0",
"vuetify": "^1.0.17",
"webextension-polyfill": "^0.2.1"
"webextension-polyfill": "^0.3.1"
},
"devDependencies": {
"babel-core": "^6.26.3",
Expand Down
14 changes: 6 additions & 8 deletions src/common/service/boss.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ const getToken = async (auth) => {

const fetchData = async (uri = '', method = 'GET', data = {}) => {
const headers = new Headers
const token = await getToken().catch(async err => {
console.error(err)
await new Promise(resolve => setTimeout(resolve), 5000)
return getToken()
})
const token = await getToken()
if (token) headers.append(tokenHeader, token)

const option = {
Expand All @@ -68,7 +64,8 @@ const fetchData = async (uri = '', method = 'GET', data = {}) => {
return fetch(apiUrl + uri, option)
.then(async res => {
// use new token
if (res.headers.get(tokenHeader)) {
if (res.headers.has(tokenHeader)) {
console.debug('[boss]: got new token', res.headers.get(tokenHeader))
await browser.storage.local.set({[tokenKey]: res.headers.get(tokenHeader)})
}
return res
Expand All @@ -79,9 +76,10 @@ const fetchData = async (uri = '', method = 'GET', data = {}) => {
return json
} else return res.text()
})
.catch(err => {
.catch(async err => {
// remove expired token
browser.storage.local.remove(tokenKey)
await browser.storage.local.remove(tokenKey)
await browser.storage.local.remove('sync_info')
console.error(err)
throw new Error('Internal Server Error')
})
Expand Down
32 changes: 4 additions & 28 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -482,31 +482,7 @@ babel-code-frame@^6.26.0:
esutils "^2.0.2"
js-tokens "^3.0.2"

babel-core@^6.26.0:
version "6.26.3"
resolved "http://registry.npm.taobao.org/babel-core/download/babel-core-6.26.3.tgz#b2e2f09e342d0f0c88e2f02e067794125e75c207"
dependencies:
babel-code-frame "^6.26.0"
babel-generator "^6.26.0"
babel-helpers "^6.24.1"
babel-messages "^6.23.0"
babel-register "^6.26.0"
babel-runtime "^6.26.0"
babel-template "^6.26.0"
babel-traverse "^6.26.0"
babel-types "^6.26.0"
babylon "^6.18.0"
convert-source-map "^1.5.1"
debug "^2.6.9"
json5 "^0.5.1"
lodash "^4.17.4"
minimatch "^3.0.4"
path-is-absolute "^1.0.1"
private "^0.1.8"
slash "^1.0.0"
source-map "^0.5.7"

babel-core@^6.26.3:
babel-core@^6.26.0, babel-core@^6.26.3:
version "6.26.3"
resolved "https://registry.npmjs.org/babel-core/-/babel-core-6.26.3.tgz#b2e2f09e342d0f0c88e2f02e067794125e75c207"
dependencies:
Expand Down Expand Up @@ -6629,9 +6605,9 @@ [email protected]:
"@webassemblyjs/wast-parser" "1.3.1"
long "^3.2.0"

webextension-polyfill@^0.2.1:
version "0.2.1"
resolved "http://registry.npm.taobao.org/webextension-polyfill/download/webextension-polyfill-0.2.1.tgz#cdfc9126033039f1713553157d35beff1d4d6f4a"
webextension-polyfill@^0.3.1:
version "0.3.1"
resolved "https://registry.npmjs.org/webextension-polyfill/-/webextension-polyfill-0.3.1.tgz#fab2aed917a713a5d8221e41febad81c5d0b080f"

webpack-addons@^1.1.5:
version "1.1.5"
Expand Down

0 comments on commit a81b92e

Please sign in to comment.