gitroomhq/postiz-app · warning · Error

Failed to get original link: ${error}

Error message

Failed to get original link: ${error}

What it means

Catch-all wrapper in convertShortLinkToLink: any failure resolving a short link (inner HTTP status throw, network error, invalid JSON) is re-thrown as 'Failed to get original link: <cause>'. The underlying reason is embedded in the message text.

Source

Thrown at libraries/nestjs-libraries/src/short-linking/providers/kutt.ts:88

  }

  async convertShortLinkToLink(shortLink: string) {
    const linkId = shortLink.split('/').pop();
    
    try {
      const response = await fetch(
        `${KUTT_API_ENDPOINT}/links/${linkId}/stats`,
        getOptions()
      );

      if (!response.ok) {
        throw new Error(`HTTP error! status: ${response.status}`);
      }

      const data = await response.json();
      return data.address || '';
    } catch (error) {
      throw new Error(`Failed to get original link: ${error}`);
    }
  }

  async getAllLinksStatistics(
    id: string,
    page = 1
  ): Promise<{ short: string; original: string; clicks: string }[]> {
    try {
      const response = await fetch(
        `${KUTT_API_ENDPOINT}/links?limit=100&skip=${(page - 1) * 100}`,
        getOptions()
      );

      if (!response.ok) {
        throw new Error(`HTTP error! status: ${response.status}`);
      }

      const data = await response.json();

View on GitHub (pinned to 0f1647f749)

Solutions

  1. Inspect the wrapped cause in the message and fix per status (401 key, 404 unknown link)
  2. Catch this at the call site and fall back to the short link itself or '' since resolution is best-effort
  3. Ensure KUTT_* env vars are consistent across deployments

Example fix

// before
} catch (error) {
  throw new Error(`Failed to get original link: ${error}`);
}

// after
} catch (error) {
  return ''; // resolution is best-effort; degrade gracefully
}
Defensive patterns

Strategy: fallback

Validate before calling

if (!process.env.KUTT_API_KEY) return '';

Type guard

function isOriginalLinkError(e: unknown): e is Error {
  return e instanceof Error && e.message.startsWith('Failed to get original link:');
}

Try / catch

try {
  original = await kutt.convertShortLinkToLink(short);
} catch (error) {
  this.logger.debug(`Unresolvable short link ${short}: ${error}`);
  original = short;
}

Prevention

When it happens

Trigger: The GET /links/{id}/stats call throws for any reason — 404 unknown id, 401 bad key, DNS failure to KUTT_API_ENDPOINT — and the catch re-wraps it.

Common situations: Expired/deleted short links being resolved during analytics or repost flows; env misconfiguration between environments (staging key vs prod Kutt instance).

Related errors


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