Skip to content

Commit

Permalink
fix(dev): catch no context for middleware;
Browse files Browse the repository at this point in the history
- Catch `TypeError` if there is no registered context for the request.
  • Loading branch information
JVickery-TBS committed Aug 25, 2023
1 parent 12c8d05 commit 3cff59c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ckanext/canada/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from ckan.plugins.toolkit import (
c,
g,
h,
chained_action,
ValidationError,
Expand Down Expand Up @@ -702,11 +703,15 @@ def __init__(self, app, config):
def __call__(self, environ, start_response):
def _start_response(status, response_headers, exc_info=None):
extra = []
if c.user:
log_extra = c.log_extra if hasattr(c, 'log_extra') else u''
try:
contextual_user = g.user
except TypeError:
contextual_user = None
if contextual_user:
log_extra = g.log_extra if hasattr(g, 'log_extra') else u''
extra = [(
'X-LogExtra', u'user={uid} {extra}'.format(
uid=c.user,
uid=contextual_user,
extra=log_extra).encode('utf-8')
)
]
Expand Down

0 comments on commit 3cff59c

Please sign in to comment.