Updated middleware class to check for Exceptions or return an HttpResponse object if the user does not have permissions to the app.