@@ -71,6 +71,61 @@ from ..const import (
7171 API_LIST_TITLE_RIS_KEY ,
7272
7373
74+ # # ... source file abbreviated to get to BadRequest examples ...
75+
76+
77+ API_SELECT_COLUMNS_RIS_KEY ,
78+ API_SHOW_COLUMNS_RES_KEY ,
79+ API_SHOW_COLUMNS_RIS_KEY ,
80+ API_SHOW_TITLE_RES_KEY ,
81+ API_SHOW_TITLE_RIS_KEY ,
82+ API_URI_RIS_KEY ,
83+ PERMISSION_PREFIX ,
84+ )
85+ from ..exceptions import FABException, InvalidOrderByColumnFABException
86+ from ..security.decorators import permission_name, protect
87+
88+ log = logging.getLogger(__name__ )
89+
90+
91+ def get_error_msg ():
92+ if current_app.config.get(" FAB_API_SHOW_STACKTRACE" ):
93+ return traceback.format_exc()
94+ return " Fatal error"
95+
96+
97+ def safe (f ):
98+
99+ def wraps (self , * args , ** kwargs ):
100+ try :
101+ return f(self , * args, ** kwargs)
102+ ~~ except BadRequest as e:
103+ return self .response_400(message = str (e))
104+ except Exception as e:
105+ logging.exception(e)
106+ return self .response_500(message = get_error_msg())
107+
108+ return functools.update_wrapper(wraps, f)
109+
110+
111+ def rison (schema = None ):
112+
113+ def _rison (f ):
114+ def wraps (self , * args , ** kwargs ):
115+ value = request.args.get(API_URI_RIS_KEY , None )
116+ kwargs[" rison" ] = dict ()
117+ if value:
118+ try :
119+ kwargs[" rison" ] = prison.loads(value)
120+ except prison.decoder.ParserException:
121+ if current_app.config.get(" FAB_API_ALLOW_JSON_QS" , True ):
122+ try :
123+ kwargs[" rison" ] = json.loads(
124+ urllib.parse.parse_qs(f " { API_URI_RIS_KEY } = { value} " ).get(
125+ API_URI_RIS_KEY
126+ )[0 ]
127+
128+
74129# # ... source file continues with no further BadRequest examples...
75130
76131```
0 commit comments