infiniflow/ragflow · error · Error

Request failed

Error message

Request failed

What it means

This error is thrown by the SkillSpaceService.request wrapper in web/src/services/skill-space-service.ts:134 whenever the backend responds with a JSON body whose `code` field is anything other than 0. The wrapper normalizes every skill-space endpoint (listSpaces, createSpace, getSpace, etc.) through one path, so a non-zero code from ANY of these APIs surfaces as 'Request failed' when the response omits a `message` field. It is not a network error; the HTTP request completed and returned an application-level failure envelope.

Source

Thrown at web/src/services/skill-space-service.ts:134

}

class SkillSpaceService {
  private async request<T>(
    method: string,
    url: string,
    data?: any,
    params?: any,
  ): Promise<T> {
    const response: any = await request(url, {
      method: method as any,
      data,
      params,
    });

    const jsonData = response?.data ?? response;

    if (jsonData?.code !== 0) {
      throw new Error(jsonData?.message || 'Request failed');
    }

    return jsonData.data;
  }

  // ==================== Skill Space Management ====================

  // List all skill spaces
  async listSpaces(): Promise<{ spaces: SkillSpace[]; total: number }> {
    return await this.request<{ spaces: SkillSpace[]; total: number }>(
      'GET',
      api.skillSpaces,
    );
  }

  // Create a new skill space
  async createSpace(request: CreateSpaceRequest): Promise<SkillSpace> {
    return await this.request<SkillSpace>('POST', api.skillSpaces, request);

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Check the browser Network tab for the actual response body of the failing skill-space request to see the real code and any message
  2. If the response is not JSON (HTML error page, empty body), fix the server/proxy issue — the wrapper misclassifies it as an app error
  3. Improve the wrapper to include `code` in the thrown message (e.g. `Request failed (code ${jsonData?.code})`) so failures are diagnosable
  4. Verify the session token is valid and the request reached the RAGFlow API server rather than a gateway error page

Example fix

// before
if (jsonData?.code !== 0) {
  throw new Error(jsonData?.message || 'Request failed');
}

// after
if (jsonData?.code !== 0) {
  const detail = jsonData?.message || 'Request failed';
  throw new Error(`${detail} (code: ${jsonData?.code ?? 'no-code'})`);
}
Defensive patterns

Strategy: try-catch

Validate before calling

const isValidEnvelope = (d: unknown): d is { code: number; data: unknown; message?: string } =>
  typeof d === 'object' && d !== null && 'code' in d;

// before calling a skill-space mutation:
if (!spaceName?.trim()) {
  throw new Error('Space name is required'); // prevent obvious server-side rejections
}

Type guard

function isSkillSpaceEnvelope(v: any): v is { code: number; message?: string; data: any } {
  return typeof v?.code === 'number';
}

Try / catch

try {
  const spaces = await skillSpaceService.listSpaces();
} catch (e) {
  const msg = e instanceof Error ? e.message : String(e);
  if (/code:\s*(?!0)/.test(msg)) {
    // application-level rejection — surface message to user, do not retry
    notification.error({ description: msg });
  } else {
    throw e; // transport/proxy issue — let React Query retry
  }
}

Prevention

When it happens

Trigger: Any SkillSpaceService call (GET api.skillSpaces, POST createSpace, GET/PUT/DELETE api.skillSpace(spaceId), skill indexing) where the server returns {code: != 0} with an empty or missing `message` — e.g. server-side validation failure, duplicate space name, or a backend exception handler that returns code 109/500 without a message. Also triggered when the response shape is unexpected (jsonData is null/undefined after `response?.data ?? response`), making `code` undefined !== 0.

Common situations: Backend returns a raw string or HTML error page (proxy 502/504) that axios wraps so jsonData has no `code`; API base URL points to the wrong server; backend version mismatch where new error codes lack messages; expired auth token causing a redirect/HTML login page instead of JSON.

Related errors


AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15). Data as JSON: /api/errors/9b18245366f1f946. Report an issue: GitHub.