TrainingByPackt/Python-API-Development-Fundamentals

Exercise 33 Code Issues

rolimatrix opened this issue · 0 comments

In Class \Ressources\User.py you wrote this Code:
class UserListResource(Resource):
def post(self):

    json_data = request.get_json()
    data, errors = user_schema.load(data=json_data)

But data, errors = user_schema.load(data=json_data) will ever issue execptions.

I changed with: from marshmallow import ValidationError
to:
try:
data = user_schema.load(data=json_data)
except ValidationError as errors:
return {'message': 'Validation errors', 'errors': errors.messages}, HTTPStatus.BAD_REQUEST

Now its working very well.