10
10
from werkzeug .exceptions import HTTPException
11
11
import re
12
12
import sys
13
+ from flask import __version__ as flask_version
13
14
14
15
15
16
api_resources = Blueprint (
@@ -88,9 +89,15 @@ def handle_user_exception(self, e):
88
89
if handlers is not None :
89
90
blueprint_handlers = handlers .get (None , ())
90
91
app_handlers = self .error_handler_spec [None ].get (None , ())
91
- for typecheck , handler in chain (blueprint_handlers .items (), app_handlers .items ()):
92
- if isinstance (e , typecheck ):
93
- return handler (e )
92
+ flask_version .split ()
93
+ if self .get_minor_version () <= 10 :
94
+ for typecheck , handler in chain (blueprint_handlers , app_handlers ):
95
+ if isinstance (e , typecheck ):
96
+ return handler (e )
97
+ else :
98
+ for typecheck , handler in chain (blueprint_handlers .items (), app_handlers .items ()):
99
+ if isinstance (e , typecheck ):
100
+ return handler (e )
94
101
95
102
reraise (exc_type , exc_value , tb )
96
103
@@ -116,3 +123,7 @@ def create_url_adapter(self, request):
116
123
self .config ['SERVER_NAME' ],
117
124
script_name = self .config ['APPLICATION_ROOT' ] or '/' ,
118
125
url_scheme = self .config ['PREFERRED_URL_SCHEME' ])
126
+
127
+ @staticmethod
128
+ def get_minor_version ():
129
+ return int (flask_version .split ("." )[1 ])
0 commit comments