fix: Parse JSON content in WebSocket message validator
**Motivations :** - Fix WebSocket message validation that was rejecting valid handshake messages - Allow content to be either object or JSON string as per protocol **Modifications :** - Updated validateMessageStructure to parse JSON string content - Added proper error handling for invalid JSON strings - Maintained backward compatibility with object content **Pages affectées :** - src/services/message-validator.ts - Enhanced content validation
This commit is contained in:
parent
08a47fab3e
commit
a96a292089
@ -106,9 +106,17 @@ export class MessageValidator {
|
|||||||
return { isValid: false, errors };
|
return { isValid: false, errors };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vérifier le type du contenu
|
// Vérifier le type du contenu - peut être un objet ou une string JSON
|
||||||
if (typeof message.content !== 'object') {
|
if (typeof message.content === 'string') {
|
||||||
errors.push('Content must be an object');
|
// Parser le contenu JSON si c'est une string
|
||||||
|
try {
|
||||||
|
message.content = JSON.parse(message.content);
|
||||||
|
} catch (error) {
|
||||||
|
errors.push('Content must be valid JSON if it is a string');
|
||||||
|
return { isValid: false, errors };
|
||||||
|
}
|
||||||
|
} else if (typeof message.content !== 'object') {
|
||||||
|
errors.push('Content must be an object or valid JSON string');
|
||||||
return { isValid: false, errors };
|
return { isValid: false, errors };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user