Beispiel #1
0
def error_response(client: api.API, e: exceptions.ClientError):
    return web.json_response(data={
        'code': 500,
        'msg': str(e),
        'platform': client.platform_id(),
    },
                             status=500)
Beispiel #2
0
def success_response(client: api.API, data: dict):
    return web.json_response(data={
        'code': 200,
        'data': data,
        'platform': client.platform_id(),
    },
                             status=200)
Beispiel #3
0
async def get_album(client: api.API, album_id: str):
    try:
        resp = await client.get_album(album_id)
    except exceptions.ClientError as e:
        await client.close()
        return web.json_response(data={
            'code': 500,
            'msg': str(e),
            'platform': client.platform(),
        },
                                 status=500)

    await client.close()
    return web.json_response(data={
        'code': 200,
        'data': resp.serialize(),
        'platform': client.platform(),
    },
                             status=200)
Beispiel #4
0
async def search_songs(client: api.API, keyword: str):
    try:
        resp = await client.search_songs(keyword)
    except exceptions.ClientError as e:
        await client.close()
        return web.json_response(data={
            'code': 500,
            'msg': str(e),
            'platform': client.platform(),
        },
                                 status=500)

    await client.close()
    return web.json_response(data={
        'code': 200,
        'data': resp.serialize(),
        'platform': client.platform(),
    },
                             status=200)