anuraghazra/github-readme-stats · error · CustomError

WAKATIME_USER_NOT_FOUND

WAKATIME_USER_NOT_FOUND

Error message

Could not resolve to a User with the login of '${username}'

What it means

Raised when the WakaTime REST GET returns any non-2xx status: the condition `err.response.status < 200 || err.response.status > 299` maps every non-success HTTP code to a single WAKATIME_USER_NOT_FOUND type, which is imprecise (a 401, 500, or 503 is labeled 'user not found'). The secondary message (src/common/error.js:19) is "Make sure you have a public WakaTime profile", pointing at the most common real cause: a private or nonexistent WakaTime profile. Note the latent bug: if axios has no response object (DNS failure, timeout, network error), err.response is undefined and `err.response.status` throws a TypeError before this CustomError can be constructed.

Source

Thrown at src/fetchers/wakatime.js:27

 * @param {{username: string, api_domain: string }} props Fetcher props.
 * @returns {Promise<import("./types").WakaTimeData>} WakaTime data response.
 */
const fetchWakatimeStats = async ({ username, api_domain }) => {
  if (!username) {
    throw new MissingParamError(["username"]);
  }

  try {
    const { data } = await axios.get(
      `https://${
        api_domain ? api_domain.replace(/\/$/gi, "") : "wakatime.com"
      }/api/v1/users/${username}/stats?is_including_today=true`,
    );

    return data.data;
  } catch (err) {
    if (err.response.status < 200 || err.response.status > 299) {
      throw new CustomError(
        `Could not resolve to a User with the login of '${username}'`,
        "WAKATIME_USER_NOT_FOUND",
      );
    }
    throw err;
  }
};

export { fetchWakatimeStats };
export default fetchWakatimeStats;

View on GitHub (pinned to 54a7985aee)

Solutions

  1. In WakaTime, set the profile to public (Settings > and enable the public profile), which is the cause implied by the secondary message.
  2. Verify the username exists by opening https://wakatime.com/@<username>.
  3. If using a custom api_domain, confirm it is correct, reachable, and does not require authentication this fetcher does not send.
  4. Check https://status.wakatime.com for an active outage when the username and profile are known-good.
  5. Guard against network-level failures: if err.response is undefined (no response), do not dereference err.response.status; surface the network error instead.

Example fix

// before
} catch (err) {
  if (err.response.status < 200 || err.response.status > 299) {
    throw new CustomError(
      `Could not resolve to a User with the login of '${username}'`,
      "WAKATIME_USER_NOT_FOUND",
    );
  }
  throw err;
}

// after (distinguish 404 from other statuses, avoid crash on no response)
} catch (err) {
  const status = err.response?.status;
  if (status === 404) {
    throw new CustomError(
      `Could not resolve to a User with the login of '${username}'`,
      "WAKATIME_USER_NOT_FOUND",
    );
  }
  throw err; // 401/500/network errors surface with their real cause
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Preflight the WakaTime profile is public before relying on fetchWakatimeStats
async function assertWakatimeProfilePublic(username, api_domain) {
  const base = api_domain ? api_domain.replace(/\/$/i, "") : "wakatime.com";
  const resp = await axios.get(
    `https://${base}/api/v1/users/${username}/stats?is_including_today=true`,
    { validateStatus: () => true },
  );
  if (resp.status === 404) throw new Error(`WakaTime user '${username}' not found`);
  if (resp.status === 401 || resp.status === 403) {
    throw new Error(`WakaTime profile for '${username}' is private; enable public profile`);
  }
  if (resp.status < 200 || resp.status > 299) {
    throw new Error(`WakaTime API returned ${resp.status}`);
  }
}
// call before fetchWakatimeStats to fail with a precise message

Type guard

function isWakatimeUserNotFound(err) {
  return err instanceof CustomError && err.type === "WAKATIME_USER_NOT_FOUND";
}

Try / catch

try {
  const stats = await fetchWakatimeStats({ username, api_domain });
} catch (err) {
  // Guard the latent crash: a network error has no err.response
  if (!err.response && !(err instanceof CustomError)) {
    throw new Error("Network error contacting WakaTime API");
  }
  if (err instanceof CustomError && err.type === "WAKATIME_USER_NOT_FOUND") {
    return res.send(renderError({
      message: err.message,
      secondaryMessage: "Make sure you have a public WakaTime profile",
    }));
  }
  throw err;
}

Prevention

When it happens

Trigger: The axios GET to https://<api_domain|wakatime.com>/api/v1/users/<username>/stats?is_including_today=true returns a non-2xx status with a response object. Concretely: 404 for a user that does not exist; 401/403 when the WakaTime profile is private or the self-hosted api_domain requires auth; 5xx during a WakaTime outage; a custom api_domain that is wrong or unreachable-but-responding.

Common situations: The WakaTime profile is set to private (Account Settings > not public); a typo'd WakaTime username; a self-hosted WakaTime instance (api_domain) that returns 401 without API key auth; a WakaTime service outage; pointing api_domain at the wrong host that still returns an HTTP error.

Related errors


AI-assisted analysis of anuraghazra/github-readme-stats@54a7985aee (2026-08-12). Data as JSON: /api/errors/f5e1cf16a7cb127d. Report an issue: GitHub.