def post(self, name): if StoreModel.find_by_name(name): return {'message': 'The store with name {} already exists.'.format(name)}, 404 store = StoreModel(name) try: store.save_to_db() except: return {'message': 'An error ocurred creating the store.'}, 500 return store.json(), 201
def post(self, name): if StoreModel.find_by_name(name): return {'message': 'store by name ' + name + ' already exists'} store = StoreModel(name) try: store.save_to_db() except: return {'message': 'An error occured while inserting'}, 500 return store.json(), 201
def post(self, name): if StoreModel.find_by_name(name): return {'message': "A Store with name '{}' already exists.".format(name)}, 400 store = StoreModel(name) try: store.save_to_db() except: return {'message': 'An error occurred while creating the store'}, 500 return store.json(), 201
def post(self, name): if StoreModel.find_by_name(name): return { "message": "a store with name '{}' already exists".format(name) } store = StoreModel(name) try: store.save_to_db() except Exception as e: return { "message": "an error occurred while creating the store" }, 500 return store.json(), 201
def post(self, name): if StoreModel.find_by_name(name): return {'message': f'A store with name {name} already exists'} store = StoreModel(name) try: store.save_to_db() except: return { 'message': 'An error occured while creating the store' }, 500 return store.json(), 201
def post(self, name): store = StoreModel.find_by_name(name) if store: return { "message": "There is already a store with name {}".format(store.name) }, 400 store = StoreModel(name) try: store.save_to_db() except: return {"message": "An error occurred inserting the item."}, 500 return store.json(), 201 # code for created ok
def post(self, name): if StoreModel.find_by_name(name): return { "message": "A store named '{}' already exists!".format(name) }, 400 # Bad request for data store = StoreModel(name) try: store.save_to_db() except: return { "message": "The was an error inserting the store in database" }, 500 # Internal error return store.json(), 201 # Successfully created
def post(name: str) -> tuple: """ Creates a new store. :param name: Name of the store. :return: store in .json or error message. """ store = StoreModel.find_by_name(name) if store: return { 'message': "An store with name '{}' already exists.".format(name) }, 422 # Un-processable Entity store = StoreModel(name) try: store.save_to_db() except SQLAlchemyError: return {'message': "Internal server error!"}, 500 return store.json(), 200