Add: recognize token error as grant error

This commit is contained in:
eight04 2021-12-09 00:19:33 +08:00
parent 0d283a8396
commit 66220848f1
2 changed files with 12 additions and 11 deletions

View File

@ -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;
}

View File

@ -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');