Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Commit 0f040c2

Browse files
committed
catch undefined exceptions, print traceback
1 parent cd3e0e2 commit 0f040c2

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

flask_mongorest/views.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
2+
import sys
23
import time
34
import json
45
import boto3
56
import hashlib
7+
import traceback
68
import mongoengine
79
from gzip import GzipFile
810
from io import BytesIO
@@ -135,6 +137,12 @@ def _dispatch_request(self, *args, **kwargs):
135137
return {'error': str(e)}, '401 Unauthorized'
136138
except (NotFound, mongoengine.queryset.DoesNotExist) as e:
137139
return {'error': str(e)}, '404 Not Found'
140+
except Exception as e:
141+
exc_type, exc_value, exc_tb = sys.exc_info()
142+
tb = traceback.format_exception(exc_type, exc_value, exc_tb)
143+
err = ''.join(tb)
144+
print(err)
145+
return {'error': err}, '500 Internal Server Error'
138146

139147
def handle_validation_error(self, e):
140148
if isinstance(e, ValidationError):

0 commit comments

Comments
 (0)