implemented server#136
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Thank you for your hard work on this project! There are a few critical issues that need to be addressed before we can approve the pull request:
-
Error Handling: The server currently uses a 404 status code for missing data, which is not appropriate. Please update this to use a 400 status code to indicate a "Bad Request" when the data is missing or incorrect.
-
Data Persistence: The current implementation of
fs.writeFileoverwrites theexpense.jsonfile with each new request. If the goal is to append new expenses, consider usingfs.appendFileor read the existing data, append the new expense, and then write it back. -
Amount Field: The
amountfield inexpense.jsonis set tonull. Ensure that the server correctly parses and stores theamountvalue from incoming requests.
Once these issues are resolved, your code will be in great shape! Keep up the good work, and don't hesitate to reach out if you need any help. 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review button in the Reviewers tab.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great progress on the code! 🎉 You've made some significant improvements, especially in error handling by using a 400 status code for missing fields, which aligns well with best practices. However, there are still a few critical issues to address:
-
Data Persistence: The current use of
fs.writeFileoverwrites theexpense.jsonfile. To ensure new expenses are appended, consider usingfs.appendFileor read the existing data, append the new expense, and then write it back. -
Parsing Logic: The
parseExpenseDatafunction currently attempts to parse the body as JSON first. Ensure the incoming data format is consistent with this approach. If the data is always in querystring format, this JSON parsing might be unnecessary. -
Error Handling: Using a 404 status code for invalid URLs is not appropriate for bad requests. Consider using a 400 status code to indicate a 'Bad Request'.
These changes are crucial for maintaining data integrity and ensuring the server handles requests correctly. Keep up the good work, and make sure to address these issues in future iterations to enhance your learning experience. Remember, every challenge is an opportunity to learn and grow! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
Form data