LUN-1869: Since we are managing the state of the current site id, it is important to sync the CMS_TEMPLATES variables as sooner as possible in the request/response cycle, so that even on early middleware chain breaking, the error page will be displayed correctly with respect to the current site. This fix also ensures that we are able to show the CMS error page even if there is an early exception raised in the middleware chain
LUN-1869: Set CMS_TEMPLATES only on exceptional case in SiteIdPatchMiddleware and don't care about interfering in the exception flow (a 404 could possibly be transformed into a 500)
LUN-1869: Small improvement
Update middleware.py

LUN-1869: Make sure the default templates for the current request are set (even if 404 is raised).
Set the default CMS_TEMPLATES at the beginning
Merge pull request #32 from pbs/LUN-1869

LUN-1869: Since we are managing the state of the current site id, it is ...