gitroomhq/postiz-app · error · BadBody

${handleError?.value || response?.message || 'Could not refr

Error message

${handleError?.value || response?.message || 'Could not refresh the TikTok access token'}

What it means

refreshToken exchanges a refresh_token at TikTok's OAuth endpoint. TikTok signals OAuth failure with HTTP 200 and a non-zero code (and no data.access_token), so this BadBody surfaces TikTok's reason rather than a TypeError from destructuring an undefined token.

Source

Thrown at libraries/nestjs-libraries/src/integrations/social/tiktok.business.provider.ts:318

        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({
          client_id: process.env.TIKTOK_BUSINESS_CLIENT_ID!,
          client_secret: process.env.TIKTOK_BUSINESS_CLIENT_SECRET!,
          grant_type: 'refresh_token',
          refresh_token: refreshToken,
        }),
      })
    ).json();

    // OAuth failures also arrive as HTTP 200 with a non-zero code and no data -
    // without this check the destructure below throws an unclassified TypeError.
    if (response?.code !== 0 || !response?.data?.access_token) {
      const asString = JSON.stringify(response);
      const handleError = this.handleErrors(asString);
      throw new BadBody(
        'tiktok-business',
        asString,
        Buffer.from('{}'),
        handleError?.value ||
          response?.message ||
          'Could not refresh the TikTok access token'
      );
    }

    const { access_token, refresh_token, open_id } = response.data;

    const { display_name, profile_image, username } =
      await this.fetchUserInformation(access_token, open_id);

    return {
      refreshToken: refresh_token,
      expiresIn: dayjs().add(23, 'hours').unix() - dayjs().unix(),
      accessToken: access_token,

View on GitHub (pinned to 0f1647f749)

Solutions

  1. Verify client_key/client_secret env values match the TikTok app
  2. Ask the user to reconnect the channel if the refresh token was revoked/expired
  3. Compare redirect_uri against the app's registered URL exactly
  4. Log the full response JSON to see TikTok's specific code/message
Defensive patterns

Strategy: retry

Try / catch

try { await refreshToken(channel); } catch (e) { if (/refresh the TikTok access token/.test(e.message)) markChannelForReconnect(channel.id); throw e; }

Prevention

When it happens

Trigger: refresh_token expired or revoked (user disconnected the app), client_secret mismatch, or grant_type/redirect_uri parameters wrong for the Business API.

Common situations: Long-unused channels whose refresh token passed TikTok's 365-day limit, rotated client secrets not updated in env config, or redirect_uri differing from the registered one.

Related errors


AI-assisted analysis of gitroomhq/postiz-app@0f1647f749 (2026-08-27). Data as JSON: /api/errors/180be1c87688a239. Report an issue: GitHub.