From 66220848f18c03a5486ed35b2a04476ce45a0fc7 Mon Sep 17 00:00:00 2001 From: eight04 Date: Thu, 9 Dec 2021 00:19:33 +0800 Subject: [PATCH] Add: recognize token error as grant error --- background/sync-manager.js | 1 + background/token-manager.js | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/background/sync-manager.js b/background/sync-manager.js index 91a0753a..cb51498d 100644 --- a/background/sync-manager.js +++ b/background/sync-manager.js @@ -220,6 +220,7 @@ const syncMan = (() => { function isGrantError(err) { if (err.code === 401) return true; if (err.code === 400 && /invalid_grant/.test(err.message)) return true; + if (err.name === 'TokenError') return true; return false; } diff --git a/background/token-manager.js b/background/token-manager.js index c06926d2..c50090ef 100644 --- a/background/token-manager.js +++ b/background/token-manager.js @@ -63,6 +63,17 @@ const tokenMan = (() => { let alwaysUseTab = FIREFOX ? false : null; + class TokenError extends Error { + constructor(provider, message) { + super(`[${provider}] ${message}`); + this.name = 'TokenError'; + this.provider = provider; + if (Error.captureStackTrace) { + Error.captureStackTrace(this, TokenError); + } + } + } + return { buildKeys(name, hooks) { @@ -112,17 +123,6 @@ const tokenMan = (() => { }, }; - class TokenError extends Error { - constructor(provider, message) { - super(`[${provider}] ${message}`); - this.name = 'TokenError'; - this.provider = provider; - if (Error.captureStackTrace) { - Error.captureStackTrace(this, TokenError); - } - } - } - async function refreshToken(name, k, obj) { if (!obj[k.REFRESH]) { throw new TokenError(name, 'No refresh token');