f1nal3 / Juniorgram

A C++ messenger for learning purposes in EPAM Brest C++ R&D Lab
14 stars 1 forks source link

Creating a server response error container and improving message processing methods #655

Closed memorisecodead closed 1 year ago

memorisecodead commented 1 year ago

Idea:

The explicit processing of the correctness of the responses on the server side requires modification of the server methods responsible for the formation of responses. This will help to track down invalid responses by storing invalid responses in a queue (you can use a vector). This will allow us to know which responses have been processed incorrectly and will also give us control over the messages.

Workflow:

Situation: Sending a message. Process the message on the server side (std::optional Server::registrationRequest(std::shared_ptr client, const Message& message) const):

  1. In case of error, return from std::optional function, where MessageResult::InvalidBody, otherwise MessageResult::Success.
  2. If returned Result = MessageResult::InvalidBody, then in the onMessage function, we check Result: if Result == Error, we put Error in the error container, otherwise we put MessageResult::Success.

    Example:

    You can see an example of this offer in our test client. I will attach the snippets: [Link to Client.TestObject] image In the method we create the data type std::optional, which is responsible for the result of the message response. If the response to messages was executed correctly, the result becomes valid, otherwise if the result becomes invalid and is sent to the error queue declared by the class variable: image