Usman/lms11189 user api middleware exception 2

LMS-11189

#4670 with another commit
@flowerhack The goal of this fix is that the middleware should not raise an exception and should return `None` if the course_id is invalid. It is not visible in the diff but `self.process_request()` asserts that. So I think this is a sufficient failing test.