def put(body): for song in body: try: Song.add_entry(song) except IntegrityError: orm.rollback() return { "message": "song of id {} already exists, aborting insert".format( song.get('id')) }, 400 except TransactionIntegrityError: orm.rollback() return { "message": "song of id {} already exists, aborting insert".format( song.get('id')) }, 400 except Exception as e: orm.rollback() logger.error(e) return { "message": "failed to insert the song of id {}, unknown error, check log for more info." " TIMESTAMP {}".format(song.get('id'), time.asctime()) }, 400 return {"message": "Successfully inserted {} songs".format(len(body))}, 200