Skip to content

Commit

Permalink
show trace if error
Browse files Browse the repository at this point in the history
  • Loading branch information
delcroip committed Oct 19, 2024
1 parent 6c7bb26 commit 9f63fab
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions api_fhir_r4/exceptions/fhir_api_exception_handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from rest_framework import status
from rest_framework.response import Response
from rest_framework import exceptions, status, views
from api_fhir_r4.exceptions import FHIRException

from django.conf import settings
import traceback
import logging

logger = logging.getLogger(__name__)

def call_default_exception_handler(exc, context):
# Call REST framework's default exception handler first, to get the standard error response.
Expand All @@ -20,8 +26,18 @@ def fhir_api_exception_handler(exc, context):
if 'api_fhir_r4' in request_path:
from api_fhir_r4.converters import OperationOutcomeConverter
fhir_outcome = OperationOutcomeConverter.to_fhir_obj(exc)
if settings.DEBUG and not isinstance(exc, (
exceptions.NotAuthenticated,
exceptions.AuthenticationFailed,
exceptions.PermissionDenied,
FHIRException
)):
trace = traceback.extract_tb(traceback.sys.exc_info()[2])
logger.debug("Unexpected {exc.__class__.__name__} trace:\n" + ''.join(traceback.format_list(trace)))

if not response:
response = __create_server_error_response()

response.data = fhir_outcome.dict()

return response
Expand Down

0 comments on commit 9f63fab

Please sign in to comment.