File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 33Copyright (c) 2019 - present AppSeed.us
44"""
55
6+ import json
7+
68from flask import Flask
79
810from .routes import rest_api , jwt
1517db .init_app (app )
1618rest_api .init_app (app )
1719jwt .init_app (app )
20+
21+
22+ """
23+ Custom responses
24+ """
25+
26+ @app .after_request
27+ def after_request (response ):
28+ """
29+ Sends back a custom error with {"success", "msg"} format
30+ """
31+
32+ if int (response .status_code ) >= 400 :
33+ response_data = json .loads (response .get_data ())
34+ if "errors" in response_data :
35+ _err_keys = response_data .keys ()
36+ response_data = {"success" : False ,
37+ "msg" : list (response_data ["errors" ].items ())[0 ][1 ]}
38+ response .set_data (json .dumps (response_data ))
39+ response .headers .add ('Content-Type' , 'application/json' )
40+ return response
You can’t perform that action at this time.
0 commit comments