fix(TypedServer): Improve error handling in server startup and response buffering. Validate configuration for reload injections, wrap file watching and TypedSocket initialization in try/catch blocks, enhance client notification and stop procedures, and ensure proper Buffer conversion in the proxy handler.

This commit is contained in:
2025-03-16 12:02:49 +00:00
parent 0dcb9edcbe
commit d5f7fbbb9a
4 changed files with 137 additions and 52 deletions

View File

@ -40,12 +40,21 @@ export class HandlerProxy extends Handler {
}
}
let responseToSend: Buffer = proxiedResponse.body;
// Ensure body exists and convert it to Buffer consistently
let responseToSend: Buffer;
// Remove incorrect type check that expects responseToSend to be a string
// Instead, ensure it's a Buffer for consistent handling
if (!Buffer.isBuffer(responseToSend)) {
responseToSend = Buffer.from(responseToSend.toString());
if (proxiedResponse.body !== undefined && proxiedResponse.body !== null) {
if (Buffer.isBuffer(proxiedResponse.body)) {
responseToSend = proxiedResponse.body;
} else if (typeof proxiedResponse.body === 'string') {
responseToSend = Buffer.from(proxiedResponse.body);
} else {
// Handle other types (like objects) by JSON stringifying them
responseToSend = Buffer.from(JSON.stringify(proxiedResponse.body));
}
} else {
// Provide a default empty buffer if body is undefined/null
responseToSend = Buffer.from('');
}
if (optionsArg && optionsArg.responseModifier) {