justjavac/wechat-miniapp-radar · warning · Error

Upstash request failed with ${response.status}

Error message

Upstash request failed with ${response.status}

What it means

Thrown by upstashCommand() in lib/upstash.ts when the REST POST returns a non-2xx status. It formats only the status code (`Upstash request failed with <status>`) without the body. If getUpstashRedisConfig() is null (neither the UPSTASH_REDIS_REST_* nor the KV_REST_API_* pair is set), the function returns null early and never throws, so this error implies the integration IS configured but the endpoint rejected the request. Per project guidance Upstash is optional and callers should fall back to in-memory when it fails.

Source

Thrown at lib/upstash.ts:51

export function hasUpstashRedis() {
  return Boolean(getUpstashRedisConfig());
}

export async function upstashCommand<T>(command: Array<string | number>): Promise<T | null> {
  const config = getUpstashRedisConfig();
  if (!config) return null;

  const response = await fetch(config.url, {
    method: "POST",
    headers: {
      authorization: `Bearer ${config.token}`,
      "content-type": "application/json"
    },
    body: JSON.stringify(command)
  });

  if (!response.ok) {
    throw new Error(`Upstash request failed with ${response.status}`);
  }

  const payload = (await response.json()) as UpstashResponse<T>;
  if (payload.error) {
    throw new Error(payload.error);
  }

  return payload.result ?? null;
}

View on GitHub (pinned to 02a010ecea)

Solutions

  1. Use the Upstash REST URL (https://<id>.upstash.io) and its REST token, not the redis:// string and DB password.
  2. Verify the pair with EXPECT_UPSTASH_REDIS=1 npm run integrations:verify.
  3. For 429, check the Upstash daily usage dashboard and raise the plan or reduce call frequency.
  4. Wrap the call in try-catch and degrade to the in-memory fallback (the documented behavior when Upstash is unavailable).

Example fix

// before
const cached = await upstashCommand<string>(['GET', key]); // throws on 401

// after
let cached: string | null = null;
try {
  cached = await upstashCommand<string>(['GET', key]);
} catch (error) {
  cached = memoryCache.get(key) ?? null;
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
  const value = await upstashCommand<T>(command);
  return value;
} catch (error) {
  // error.message is 'Upstash request failed with <status>'
  return inMemoryFallback();
}

Prevention

When it happens

Trigger: 401/403 wrong or revoked token (UPSTASH_REDIS_REST_TOKEN / KV_REST_API_TOKEN); 404 from a wrong UPSTASH_REDIS_REST_URL (e.g. using the redis:// host instead of the https REST endpoint); 429 daily command quota exceeded on the free tier; provider 5xx; URL pasted with a wrong region.

Common situations: Copied the redis:// connection string into UPSTASH_REDIS_REST_URL instead of the REST URL; token rotated in the Upstash dashboard but not in the Vercel env; free daily limit hit by Advisor caching or rate-limit traffic; Vercel KV env vars injected under a different name than KV_REST_API_URL/KV_REST_API_TOKEN.

Related errors


AI-assisted analysis of justjavac/wechat-miniapp-radar@02a010ecea (2026-08-12). Data as JSON: /api/errors/0bfd28a59f4fe152. Report an issue: GitHub.