Skip to content

Solution#1078

Open
ZAKANDRE wants to merge 3 commits intomate-academy:masterfrom
ZAKANDRE:develop
Open

Solution#1078
ZAKANDRE wants to merge 3 commits intomate-academy:masterfrom
ZAKANDRE:develop

Conversation

@ZAKANDRE
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

This is a great start, and the core logic for text conversion is working correctly. However, some changes are needed in how error responses are handled to fully meet the project's requirements.

Specifically, there are two issues in src/createServer.js:

  1. Incorrect Status Code: For validation errors, the server currently sends a 200 OK status. This should be a 400 Bad Request to correctly indicate a client-side error.
  2. Missing Header: The 404 'Not Found' response is missing the required Content-Type: application/json header. Remember, all responses from the server must include this header.

Addressing these two points will complete the task. You're very close!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

if (req.method !== 'GET') {
res.statusCode = 404;

res.end(JSON.stringify({ error: 'Not Found' }));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task requires that all server responses have a Content-Type header for JSON. This error response is missing the res.setHeader('Content-Type', 'application/json') call.

Comment on lines +42 to +43
res.statusCode = 200;
res.statusMessage = 'OK';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the requirements, when there are validation errors, the server must respond with a 400 status code and a Bad request status message. Currently, it's sending 200 OK, which is incorrect for an error response.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Great job addressing the previous feedback! The server is very close to being complete. However, one requirement is still missing before this can be approved.

When the server responds with a 400 status code for a validation error, it also needs to include the Bad request status text. You can fix this by setting res.statusMessage = 'Bad request'; in the error handling block in src/createServer.js.

Additionally, the automated checks are failing because a line is too long on line 37. Splitting the long error message string across multiple lines will resolve this linting issue. Once these two points are addressed, your solution will be ready!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines +27 to +28
res.statusCode = 400;
res.setHeader('Content-Type', 'application/json');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This status code and header are set here, but they are also set for all errors in the if (errors.length > 0) block (lines 41-42). This makes these two lines redundant. You can remove them to make the code cleaner, as the errors are handled comprehensively later.

}

if (errors.length > 0) {
res.statusCode = 400;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task requires sending a Bad request status text along with the 400 status code. You can set this using res.statusMessage = 'Bad request';.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Great work on this task! You've successfully addressed all the previous feedback and implemented all the requirements correctly. I am approving your solution so you can move forward, but I have one small suggestion to make your code even better.

In src/createServer.js, you have some redundant code. Setting the status code, status message, and header inside the individual validation checks is unnecessary because you already handle all errors together in the if (errors.length > 0) block. Removing those repeated lines will make your code cleaner by separating the logic for collecting errors from the logic for sending the final error response.

This is just a minor point about code style, and your solution works perfectly. Well done!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Comment on lines +27 to +29
res.statusCode = 400;
res.statusMessage = 'Bad request';
res.setHeader('Content-Type', 'application/json');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job collecting all errors before sending a response! However, setting the status code, status message, and header here is redundant because this is already handled in the if (errors.length > 0) block on lines 43-45. It's best practice to separate the validation logic (collecting errors) from the response logic (sending the response) to keep the code cleaner and avoid repetition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants