diff --git a/packages/connector-google/src/index.ts b/packages/connector-google/src/index.ts index 8533f8b8a..2355f223c 100644 --- a/packages/connector-google/src/index.ts +++ b/packages/connector-google/src/index.ts @@ -106,7 +106,6 @@ export default class GoogleConnector implements SocialConnectorInstance { const { code, redirectUri } = await this.authorizationCallbackHandler(data); const { accessToken } = await this.getAccessToken(code, redirectUri); @@ -134,17 +133,7 @@ export default class GoogleConnector implements SocialConnectorInstance { + if (error instanceof HTTPError) { + const { statusCode, body: rawBody } = error.response; + + if (statusCode === 401) { + throw new ConnectorError(ConnectorErrorCodes.SocialAccessTokenInvalid); + } + + throw new ConnectorError(ConnectorErrorCodes.General, JSON.stringify(rawBody)); + } + + throw error; + }; } diff --git a/packages/connector-wechat-native/src/index.ts b/packages/connector-wechat-native/src/index.ts index d306cfbb7..97c77764e 100644 --- a/packages/connector-wechat-native/src/index.ts +++ b/packages/connector-wechat-native/src/index.ts @@ -31,7 +31,7 @@ import { accessTokenResponseGuard, GetAccessTokenErrorHandler, userInfoResponseGuard, - GetUserInfoErrorHandler, + UserInfoResponseMessageParser, WechatNativeConfig, } from './types'; @@ -107,7 +107,6 @@ export default class WechatNativeConnector implements SocialConnectorInstance { const { code } = await this.authorizationCallbackHandler(data); const { accessToken, openid } = await this.getAccessToken(code); @@ -129,21 +128,11 @@ export default class WechatNativeConnector implements SocialConnectorInstance { + private readonly userInfoResponseMessageParser: UserInfoResponseMessageParser = (userInfo) => { const { errcode, errmsg } = userInfo; if (errcode) { @@ -174,6 +163,20 @@ export default class WechatNativeConnector implements SocialConnectorInstance { + if (error instanceof HTTPError) { + const { statusCode, body: rawBody } = error.response; + + if (statusCode === 401) { + throw new ConnectorError(ConnectorErrorCodes.SocialAccessTokenInvalid); + } + + throw new ConnectorError(ConnectorErrorCodes.General, JSON.stringify(rawBody)); + } + + throw error; + }; + private readonly authorizationCallbackHandler = async (parameterObject: unknown) => { const result = codeDataGuard.safeParse(parameterObject); diff --git a/packages/connector-wechat-native/src/types.ts b/packages/connector-wechat-native/src/types.ts index d32f388c8..6b5f733cf 100644 --- a/packages/connector-wechat-native/src/types.ts +++ b/packages/connector-wechat-native/src/types.ts @@ -32,4 +32,4 @@ export const userInfoResponseGuard = z.object({ export type UserInfoResponse = z.infer; -export type GetUserInfoErrorHandler = (UserInfo: Partial) => void; +export type UserInfoResponseMessageParser = (userInfo: Partial) => void; diff --git a/packages/connector-wechat-web/src/index.ts b/packages/connector-wechat-web/src/index.ts index 7a0b1b946..7e9e38492 100644 --- a/packages/connector-wechat-web/src/index.ts +++ b/packages/connector-wechat-web/src/index.ts @@ -32,7 +32,7 @@ import { accessTokenResponseGuard, GetAccessTokenErrorHandler, userInfoResponseGuard, - GetUserInfoErrorHandler, + UserInfoResponseMessageParser, WechatConfig, } from './types'; @@ -109,7 +109,6 @@ export default class WechatConnector implements SocialConnectorInstance { const { code } = await this.authorizationCallbackHandler(data); const { accessToken, openid } = await this.getAccessToken(code); @@ -131,21 +130,11 @@ export default class WechatConnector implements SocialConnectorInstance { + private readonly userInfoResponseMessageParser: UserInfoResponseMessageParser = (userInfo) => { const { errcode, errmsg } = userInfo; if (errcode) { @@ -176,6 +165,20 @@ export default class WechatConnector implements SocialConnectorInstance { + if (error instanceof HTTPError) { + const { statusCode, body: rawBody } = error.response; + + if (statusCode === 401) { + throw new ConnectorError(ConnectorErrorCodes.SocialAccessTokenInvalid); + } + + throw new ConnectorError(ConnectorErrorCodes.General, JSON.stringify(rawBody)); + } + + throw error; + }; + private readonly authorizationCallbackHandler = async (parameterObject: unknown) => { const result = codeDataGuard.safeParse(parameterObject); diff --git a/packages/connector-wechat-web/src/types.ts b/packages/connector-wechat-web/src/types.ts index c0a5a6df6..52a7d93fc 100644 --- a/packages/connector-wechat-web/src/types.ts +++ b/packages/connector-wechat-web/src/types.ts @@ -28,4 +28,4 @@ export const userInfoResponseGuard = z.object({ export type UserInfoResponse = z.infer; -export type GetUserInfoErrorHandler = (UserInfo: Partial) => void; +export type UserInfoResponseMessageParser = (userInfo: Partial) => void;