pediatric-ai-scribe-v3/src/utils/errors.js
Daniel 2f6e5a7d8f feat: neonatal calculator, DOCX/PPTX/ODT/EPUB support, gateway-agnostic URL helper, TTS/STT fixes
- Add neonatal assessment calculator: GA classification (extremely preterm through
  post term), weight-for-GA percentile (AGA/SGA/LGA) using Fenton 2013 LMS data,
  birth weight category (ELBW/VLBW/LBW/normal/macrosomia)
- Add DOCX support via mammoth, PPTX/ODT/EPUB via jszip in Learning Hub content
  generator file upload
- Add gatewayUrl() helper for consistent API URL construction — handles
  LITELLM_API_BASE with or without /v1 suffix, works with any OpenAI-compatible
  gateway (LiteLLM, Bifrost, etc.)
- Fix TTS model/voice separation: discovery now tags items as MODEL or VOICE,
  auto-detects provider from voice name (Vertex, ElevenLabs, OpenAI)
- Fix STT discovery to include ElevenLabs Scribe and Chirp models
- Fix TTS discovery to include ElevenLabs and Vertex voices alongside models
- Fix admin model test to bypass allowlist check (skipAllowlistCheck) so
  discovered models can be tested before adding
- Fix Nextcloud token decryption in learningAI.js WebDAV browse and file import
- Fix admin embedding test to show DB model name instead of hardcoded default
- Fix admin STT test to use correct endpoint for Whisper models
- Add AI gateway migration guide to configuration docs
- Add Grafana dashboard JSON for Loki log visualization
2026-04-19 02:17:06 +02:00

28 lines
1.3 KiB
JavaScript

// ============================================================
// Error response helper — log full detail server-side, return
// generic message to client to avoid leaking stack traces and
// internal paths.
// ============================================================
function serverError(res, scope, err, publicMessage) {
try {
var msg = err && err.message ? err.message : String(err);
console.error('[' + scope + ']', msg, err && err.stack ? '\n' + err.stack : '');
} catch (e) {}
return res.status(500).json({ error: publicMessage || 'Request failed. Please try again.' });
}
// ============================================================
// AI gateway URL helper — builds endpoint URLs from
// LITELLM_API_BASE, handling both with and without /v1 suffix.
// Usage: gatewayUrl('/audio/speech') → 'https://gw.example.com/v1/audio/speech'
// The OpenAI SDK (ai.js) uses LITELLM_API_BASE directly as
// baseURL and must NOT use this helper.
// ============================================================
function gatewayUrl(path) {
var base = (process.env.LITELLM_API_BASE || '').replace(/\/+$/, '').replace(/\/v1\/?$/, '');
return base + '/v1' + (path.startsWith('/') ? path : '/' + path);
}
module.exports = { serverError: serverError, gatewayUrl: gatewayUrl };