Various minor fixes
This commit is contained in:
parent
832fa171d8
commit
1664b4aa69
@ -342,6 +342,8 @@ export class RelayManager {
|
|||||||
break;
|
break;
|
||||||
case "Commit":
|
case "Commit":
|
||||||
console.log(`📨 Commit response from relay ${relayId}`);
|
console.log(`📨 Commit response from relay ${relayId}`);
|
||||||
|
// If we receive a commit response, that's basically an error
|
||||||
|
console.error(`❌ Commit response from relay ${relayId}:`, message.error);
|
||||||
break;
|
break;
|
||||||
case "Cipher":
|
case "Cipher":
|
||||||
console.log(`📨 Cipher response from relay ${relayId}`);
|
console.log(`📨 Cipher response from relay ${relayId}`);
|
||||||
|
@ -608,7 +608,8 @@ export class Service {
|
|||||||
const result = wasm.create_update_message(process, stateId, this.membersList);
|
const result = wasm.create_update_message(process, stateId, this.membersList);
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`Failed to create update message: ${error}`);
|
const errorMessage = error instanceof Error ? error.message : String(error || 'Unknown error');
|
||||||
|
throw new Error(errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -625,7 +626,8 @@ export class Service {
|
|||||||
const result = wasm.validate_state(process, stateId, this.membersList);
|
const result = wasm.validate_state(process, stateId, this.membersList);
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`Failed to validate state: ${error}`);
|
const errorMessage = error instanceof Error ? error.message : String(error || 'Unknown error');
|
||||||
|
throw new Error(errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import { config } from './config';
|
|||||||
import { Service } from './service';
|
import { Service } from './service';
|
||||||
import { ApiReturn, Process } from '../pkg/sdk_client';
|
import { ApiReturn, Process } from '../pkg/sdk_client';
|
||||||
import { EMPTY32BYTES } from './utils';
|
import { EMPTY32BYTES } from './utils';
|
||||||
import { rust_zstd_wasm_shim_calloc } from '../pkg/sdk_client_bg.wasm';
|
|
||||||
|
|
||||||
interface ServerMessageEvent {
|
interface ServerMessageEvent {
|
||||||
data: {
|
data: {
|
||||||
@ -65,7 +64,8 @@ class SimpleProcessHandlers {
|
|||||||
res = await this.service.createPrdUpdate(processId, stateId);
|
res = await this.service.createPrdUpdate(processId, stateId);
|
||||||
await this.service.handleApiReturn(res);
|
await this.service.handleApiReturn(res);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(e as string);
|
const errorMessage = e instanceof Error ? e.message : String(e || 'Unknown error');
|
||||||
|
throw new Error(errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -73,8 +73,10 @@ class SimpleProcessHandlers {
|
|||||||
messageId: event.data.messageId
|
messageId: event.data.messageId
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const errorMsg = `Failed to notify update for process: ${e}`;
|
const errorMessage = e instanceof Error ? e.message : String(e || 'Unknown error');
|
||||||
throw new Error(errorMsg);
|
// Remove redundant "Error:" prefix and simplify the message
|
||||||
|
const cleanMessage = errorMessage.replace(/^Error:\s*/, '');
|
||||||
|
throw new Error(cleanMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +102,8 @@ class SimpleProcessHandlers {
|
|||||||
res = await this.service.approveChange(processId, stateId);
|
res = await this.service.approveChange(processId, stateId);
|
||||||
await this.service.handleApiReturn(res);
|
await this.service.handleApiReturn(res);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(e as string);
|
const errorMessage = e instanceof Error ? e.message : String(e || 'Unknown error');
|
||||||
|
throw new Error(errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -109,8 +112,10 @@ class SimpleProcessHandlers {
|
|||||||
messageId: event.data.messageId
|
messageId: event.data.messageId
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const errorMsg = `Failed to validate process: ${e}`;
|
const errorMessage = e instanceof Error ? e.message : String(e || 'Unknown error');
|
||||||
throw new Error(errorMsg);
|
// Remove redundant "Error:" prefix and simplify the message
|
||||||
|
const cleanMessage = errorMessage.replace(/^Error:\s*/, '');
|
||||||
|
throw new Error(cleanMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,7 +293,8 @@ class SimpleProcessHandlers {
|
|||||||
throw new Error(`Unhandled message type: ${event.data.type}`);
|
throw new Error(`Unhandled message type: ${event.data.type}`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return this.errorResponse(error as string, event.clientId, event.data.messageId);
|
const errorMessage = error instanceof Error ? error.message : String(error || 'Unknown error');
|
||||||
|
return this.errorResponse(errorMessage, event.clientId, event.data.messageId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -372,7 +378,11 @@ export class Server {
|
|||||||
console.log('🔑 Already paired with id:', service.getPairingProcessId());
|
console.log('🔑 Already paired with id:', service.getPairingProcessId());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Relays are automatically initialized in Service constructor
|
// Get all processes from database
|
||||||
|
await service.getAllProcessesFromDb();
|
||||||
|
|
||||||
|
// Connect to relays
|
||||||
|
await service.connectToRelaysAndWaitForHandshake();
|
||||||
|
|
||||||
console.log(`✅ Simple server running on port ${this.wss.options.port}`);
|
console.log(`✅ Simple server running on port ${this.wss.options.port}`);
|
||||||
console.log('📋 Supported operations: UPDATE_PROCESS, NOTIFY_UPDATE, VALIDATE_STATE');
|
console.log('📋 Supported operations: UPDATE_PROCESS, NOTIFY_UPDATE, VALIDATE_STATE');
|
||||||
@ -412,9 +422,10 @@ export class Server {
|
|||||||
this.sendToClient(ws, response);
|
this.sendToClient(ws, response);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`❌ Error handling message from ${clientId}:`, error);
|
console.error(`❌ Error handling message from ${clientId}:`, error);
|
||||||
|
const errorMessage = error instanceof Error ? error.message : String(error || 'Unknown error');
|
||||||
this.sendToClient(ws, {
|
this.sendToClient(ws, {
|
||||||
type: MessageType.ERROR,
|
type: MessageType.ERROR,
|
||||||
error: `Server error: ${error instanceof Error ? error.message : String(error)}`,
|
error: `Server error: ${errorMessage}`,
|
||||||
messageId: JSON.parse(data.toString())?.messageId
|
messageId: JSON.parse(data.toString())?.messageId
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user