def post(self, member_id): json_data = request.get_json() member = MemberModel(member_id, **json_data) try: member.save_to_db() except ValueError: return { "message": "An error occurred inserting the item." }, 500 # Internal server error return member.json(), 201 # created status code
def post(self, name): if MemberModel.find_by_name(name): return { "message": "Member named {} is already exists.".format(name) }, 400 member = MemberModel(name, 0) try: member.save_to_db() except: return { "message": "An error occurred while registering member." }, 500 return member.json(), 201