mirror of
https://github.com/xtr-dev/rondevu-server.git
synced 2025-12-10 10:53:24 +00:00
Fix error handling scope issue in service creation
The error handler was referencing variables (username, serviceFqn, offers) that were declared inside the try block. If an error occurred before these were defined, the error handler itself would fail, resulting in non-JSON responses that caused "JSON.parse: unexpected character" errors on the client. Fixed by: - Declaring variables at function scope - Initializing offers as empty array - Using destructuring assignment for username/serviceFqn This ensures the error handler can always access these variables safely, even if an early error occurs, and will always return proper JSON responses. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -182,9 +182,14 @@ export function createApp(storage: Storage, config: Config) {
|
||||
* Publish a service
|
||||
*/
|
||||
app.post('/services', authMiddleware, async (c) => {
|
||||
let username: string | undefined;
|
||||
let serviceFqn: string | undefined;
|
||||
let offers: any[] = [];
|
||||
|
||||
try {
|
||||
const body = await c.req.json();
|
||||
const { username, serviceFqn, sdp, ttl, isPublic, metadata, signature, message } = body;
|
||||
({ username, serviceFqn } = body);
|
||||
const { sdp, ttl, isPublic, metadata, signature, message } = body;
|
||||
|
||||
if (!username || !serviceFqn || !sdp) {
|
||||
return c.json({ error: 'Missing required parameters: username, serviceFqn, sdp' }, 400);
|
||||
@@ -230,7 +235,7 @@ export function createApp(storage: Storage, config: Config) {
|
||||
const expiresAt = Date.now() + offerTtl;
|
||||
|
||||
// Create offer first
|
||||
const offers = await storage.createOffers([{
|
||||
offers = await storage.createOffers([{
|
||||
peerId,
|
||||
sdp,
|
||||
expiresAt
|
||||
|
||||
Reference in New Issue
Block a user