3
3
"""This module contains the logic of resource management"""
4
4
5
5
import inspect
6
- import json
7
6
from six import with_metaclass
8
7
9
8
from werkzeug .wrappers import Response
10
- from flask import request , url_for , make_response , current_app
9
+ from flask import request , url_for , make_response , current_app , jsonify
11
10
from flask .views import MethodView , MethodViewType
12
11
from marshmallow_jsonapi .exceptions import IncorrectTypeError
13
12
from marshmallow import ValidationError
@@ -70,14 +69,14 @@ def dispatch_request(self, *args, **kwargs):
70
69
try :
71
70
response = method (* args , ** kwargs )
72
71
except JsonApiException as e :
73
- return make_response (json . dumps (jsonapi_errors ([e .to_dict ()])),
72
+ return make_response (jsonify (jsonapi_errors ([e .to_dict ()])),
74
73
e .status ,
75
74
headers )
76
75
except Exception as e :
77
76
if current_app .config ['DEBUG' ] is True :
78
77
raise e
79
78
exc = JsonApiException ('' , str (e ))
80
- return make_response (json . dumps (jsonapi_errors ([exc .to_dict ()])),
79
+ return make_response (jsonify (jsonapi_errors ([exc .to_dict ()])),
81
80
exc .status ,
82
81
headers )
83
82
@@ -88,7 +87,7 @@ def dispatch_request(self, *args, **kwargs):
88
87
if not isinstance (response , tuple ):
89
88
if isinstance (response , dict ):
90
89
response .update ({'jsonapi' : {'version' : '1.0' }})
91
- return make_response (json . dumps (response ), 200 , headers )
90
+ return make_response (jsonify (response ), 200 , headers )
92
91
93
92
try :
94
93
data , status_code , headers = response
@@ -104,7 +103,7 @@ def dispatch_request(self, *args, **kwargs):
104
103
if isinstance (data , dict ):
105
104
data .update ({'jsonapi' : {'version' : '1.0' }})
106
105
107
- return make_response (json . dumps (data ), status_code , headers )
106
+ return make_response (jsonify (data ), status_code , headers )
108
107
109
108
110
109
class ResourceList (with_metaclass (ResourceMeta , Resource )):
0 commit comments