from aiohttp.web import json_response async def playlist_add(request): uuid = request.match_info['uuid'] try: request.app['playlist'].put(uuid) except DuplicateTrackError: return json_response({ 'err': 'duplicate', 'msg': 'The track is already present in the playlist.' }, status=400) else: return json_response({}, status=200)