odysseus-dev/odysseus · error · Error

Server error

Error message

Server error

What it means

Thrown in documentLibrary.js's batch importer when creating a CSV document per spreadsheet sheet via POST /api/document returns non-2xx. The generic 'Server error' discards status and body; because this is inside a per-file loop, the failure aborts remaining sheets of that workbook and increments the failed counter shown in the summary.

Source

Thrown at static/js/documentLibrary.js:1546

          continue;
        }

        if (isSpreadsheet) {
          // Multi-sheet: create one document per sheet
          await ensureXLSX();
          const buf = await file.arrayBuffer();
          const wb = window.XLSX.read(buf, { type: 'array' });
          for (const sheetName of wb.SheetNames) {
            const csv = window.XLSX.utils.sheet_to_csv(wb.Sheets[sheetName]);
            if (!csv.trim()) continue;
            const sheetTitle = wb.SheetNames.length > 1
              ? `${baseTitle} - ${sheetName}` : baseTitle;
            const res = await fetch(`${API_BASE}/api/document`, {
              method: 'POST',
              headers: { 'Content-Type': 'application/json' },
              body: JSON.stringify({ title: sheetTitle, language: 'csv', content: csv }),
            });
            if (!res.ok) throw new Error('Server error');
          }
          imported++;
        } else {
          const content = await readFileContent(file);
          const res = await fetch(`${API_BASE}/api/document`, {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ title: baseTitle, language, content }),
          });
          if (!res.ok) throw new Error('Server error');
          imported++;
        }
      } catch (e) {
        console.error('Failed to import file:', file.name, e);
        if (!_firstErr) _firstErr = (e && e.message) || String(e);
        failed++;
      }
    }

View on GitHub (pinned to f9235ebbf1)

Solutions

  1. Reproduce with a single-sheet small xlsx to separate size/auth causes.
  2. Add credentials: 'same-origin' to these POST /api/document calls to match the rest of the app.
  3. Raise the JSON body limit if large sheets are expected.
  4. Include status/detail in the message instead of 'Server error'.

Example fix

// before
const res = await fetch(`${API_BASE}/api/document`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ title: sheetTitle, language: 'csv', content: csv }),
});
if (!res.ok) throw new Error('Server error');

// after
const res = await fetch(`${API_BASE}/api/document`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  credentials: 'same-origin',
  body: JSON.stringify({ title: sheetTitle, language: 'csv', content: csv }),
});
if (!res.ok) {
  let detail = '';
  try { const j = await res.json(); detail = j?.detail || j?.error || ''; } catch (_) {}
  throw new Error(`Sheet import failed (${sheetTitle}): HTTP ${res.status}${detail ? ` — ${detail}` : ''}`);
}
Defensive patterns

Strategy: validation

Validate before calling

if (!csv.trim()) continue; // skip empty sheets before hitting the API
if (csv.length > CSV_MAX_CHARS) { csv = csv.slice(0, CSV_MAX_CHARS); }

Try / catch

const res = await fetch(`${API_BASE}/api/document`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  credentials: 'same-origin',
  body: JSON.stringify({ title: sheetTitle, language: 'csv', content: csv }),
});
if (!res.ok) {
  let detail = '';
  try { const j = await res.json(); detail = j?.detail || ''; } catch (_) {}
  throw new Error(`Sheet '${sheetTitle}' import failed: HTTP ${res.status}${detail ? ' — ' + detail : ''}`);
}

Prevention

When it happens

Trigger: Sheet-to-CSV conversion succeeded but the create call rejects: content too large (413 — big sheets make huge JSON), schema validation on {title, language:'csv', content} (422), missing credentials note — these creates omit credentials: 'same-origin' unlike elsewhere — or genuine 500s.

Common situations: Importing multi-MB xlsx workbooks whose CSV expansion exceeds request limits; auth-requiring deployments where the omitted credentials cause 401; title with characters a strict backend rejects.

Related errors


AI-assisted analysis of odysseus-dev/odysseus@f9235ebbf1 (2026-08-14). Data as JSON: /api/errors/de16518fb276640a. Report an issue: GitHub.