ruvector/studio/lib/api/apiWrapper.ts
rUv 814f595995 feat(studio): Add complete RuVector Studio application
Major additions:
- Complete Next.js studio application with 1600+ components
- Docker support (Dockerfile.combined, docker-compose.yml)
- GCP deployment documentation and benchmarks
- SQL benchmark scripts for performance testing
- Sentry integration for monitoring
- Comprehensive test suite and mocks

Studio features:
- Dashboard and admin interfaces
- Data visualization components
- Authentication and user management
- API integration with RuVector backend
- Static data and public assets

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-06 23:04:48 +00:00

50 lines
1.4 KiB
TypeScript

import type { NextApiRequest, NextApiResponse } from 'next'
import { ResponseError, ResponseFailure } from 'types'
import { IS_PLATFORM } from '../constants'
import { apiAuthenticate } from './apiAuthenticate'
export function isResponseOk<T>(response: T | ResponseFailure | undefined): response is T {
if (response === undefined || response === null) {
return false
}
if (response instanceof ResponseError) {
return false
}
if (typeof response === 'object' && 'error' in response && Boolean(response.error)) {
return false
}
return true
}
// Purpose of this apiWrapper is to function like a global catchall for ANY errors
// It's a safety net as the API service should never drop, nor fail
export default async function apiWrapper(
req: NextApiRequest,
res: NextApiResponse,
handler: (req: NextApiRequest, res: NextApiResponse) => Promise<Response | void>,
options?: { withAuth: boolean }
): Promise<Response | void> {
try {
const { withAuth } = options || {}
if (IS_PLATFORM && withAuth) {
const response = await apiAuthenticate(req, res)
if (!isResponseOk(response)) {
return res.status(401).json({
error: {
message: `Unauthorized: ${response.error.message}`,
},
})
}
}
return handler(req, res)
} catch (error) {
return res.status(500).json({ error })
}
}