Usman/lms11189 user api middleware exception 2

LMS-11189

#4670 with another commit