Skip to content

London | 25-SDC-July | Andrei Filippov | Sprint 3 | Middleware exercises#24

Open
Droid-An wants to merge 6 commits intoCodeYourFuture:mainfrom
Droid-An:middleware-exercices
Open

London | 25-SDC-July | Andrei Filippov | Sprint 3 | Middleware exercises#24
Droid-An wants to merge 6 commits intoCodeYourFuture:mainfrom
Droid-An:middleware-exercices

Conversation

@Droid-An
Copy link

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

written 2 middlewares, and used built-in one

Questions

no questions

@Droid-An Droid-An added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. 📅 Sprint 3 Assigned during Sprint 3 of this module labels Sep 19, 2025
@LonMcGregor LonMcGregor added the Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. label Oct 7, 2025
Copy link
Contributor

@LonMcGregor LonMcGregor left a comment

Choose a reason for hiding this comment

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

Good work on these, the logic makes sense, however I've spotted some areas you could make improvements

app.use(assignHeader);
app.use(express.json());

// add `-H 'Content-Type: application/json'` to curl request
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this comment mean? If this is a test case I would suggest moving it to a test file, rather than leaving it as a comment inline

Copy link
Author

Choose a reason for hiding this comment

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

yeah, I agree. Since I don't have any tests in this repo, I decided to move it to the readme file because that comment is more like an instruction.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that kind of comment is more suited to the readme. Good idea

return;
}
if (
typeof body != "object" ||
Copy link
Contributor

Choose a reason for hiding this comment

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

If I pass a string like {"blah": 2}, this is a valid json string so it reaches this part of the code, but it crashes here because there's no .some() on an object, only arrays. Could you improve the input validation?

Copy link
Author

Choose a reason for hiding this comment

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

Got it. The middleware now checks if the request body is an array. I missed in the requirements that we should reject requests when the POST body is not a JSON array.
I've also updated the error message accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great! This solution looks good now

@LonMcGregor LonMcGregor added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Oct 7, 2025
@Droid-An Droid-An added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Oct 13, 2025
@github-actions
Copy link

Your PR couldn't be matched to an assignment in this module.

Please check its title is in the correct format, and that you only have one PR per assignment.

If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed).

@LonMcGregor LonMcGregor added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. 📅 Sprint 3 Assigned during Sprint 3 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants