Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great job setting up the basic server structure and correctly setting the Content-Type header. However, some changes are needed before this can be approved. The main issue is that the server always responds with a 200 OK status code. According to the requirements, when a request is invalid, the server must respond with a 400 Bad Request status. Currently, the status code in src/createServer.js is hardcoded. You'll need to update this to set the response.statusCode dynamically based on whether the request validation passes or fails.
✨ 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
| function createServer() { | ||
| const server = http.createServer((request, response) => { | ||
| response.setHeader('Content-Type', 'application/json'); | ||
| response.statusCode = 200; |
There was a problem hiding this comment.
The response status code is hardcoded to 200. According to the requirements, if the request is invalid, the server should respond with a 400 status code and 'Bad request' status text. The status code should be set dynamically after getResponseData is called, based on whether the request was valid.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great job refactoring the response logic into the getResponseData function! That's a nice improvement to the code's structure. However, this submission requires changes because the main issue from the last review hasn't been addressed: the server still sends a 200 OK status for all requests, including invalid ones that should trigger a 400 Bad Request.
To fix this, you need to dynamically set the status code in src/createServer.js based on the validation result before sending the response:
- If
responseDatacontains anerrorsproperty, setresponse.statusCode = 400andresponse.statusMessage = 'Bad request'. - If there are no errors, set
response.statusCode = 200andresponse.statusMessage = 'OK'.
Once you've implemented this, your server will be fully compliant with the requirements.
✨ 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
| response.write(JSON.stringify(responseData)); | ||
| response.statusCode = 200; | ||
| response.end(); |
There was a problem hiding this comment.
This section needs an update to meet the requirements. The status code is still hardcoded to 200, which was the main issue from the previous review.
According to the task description, you need to:
- Check if
responseDatacontains an error. - If it does, set
response.statusCodeto400andresponse.statusMessageto'Bad request'. - If it's a successful response, set
response.statusCodeto200andresponse.statusMessageto'OK'.
Also, it's important to set these properties on the response object before you send the body with response.write() or response.end().
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am approving this solution so you can move forward, but please take a moment to review the feedback for your next project.
Excellent work fixing the status code handling from the last review! The server is very close to meeting all requirements. There are just two small areas for improvement:
- In
src/createServer.js, the response for non-GETrequests (the 'Not Found' case) sends plain text. A requirement is that the server must always respond with JSON. This should be changed to send a JSON object, likeJSON.stringify({ message: 'Not Found' }). - In
src/getResponseData.js, business logic likedetectCase()is called before all validation is finished. It's best practice to perform all validation first. Only after confirming there are no errors should you call functions likedetectCaseandconvertToCase.
These changes will make your code more robust and fully compliant. You've done a great job on this task!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
|
|
||
| if (request.method !== 'GET') { | ||
| response.statusCode = 404; | ||
| response.end('Not Found'); |
There was a problem hiding this comment.
According to the "General rules" in the requirements, the server must always respond with a JSON type. This response sends a plain string instead of a JSON object. To be compliant, this should also be a JSON response, for example: JSON.stringify({ message: 'Not Found' }).
| errors.push({ message: MISSING_TEXT_ERROR }); | ||
| } | ||
|
|
||
| const originalCase = detectCase(originalText); |
There was a problem hiding this comment.
This call to detectCase happens before you've finished all the validation checks. For example, if originalText is empty, an error is added to the errors array, but this function is still executed with an empty string.
It's better practice to perform all validation first (checking originalText and targetCase). Only after confirming there are no errors should you proceed to call any business logic functions like detectCase and convertToCase.
No description provided.