# Buggy code
async def on_GET(self, request):
    server = parse_string(request, "server", default=None)

    try:
        await self.auth.get_user_by_req(request, allow_guest=True)
    except InvalidClientCredentialsError as e:
        # Option to allow servers to require auth when accessing
        # /publicRooms via CS API. This is especially helpful in private
        # federations.
        if not self.hs.config.allow_public_rooms_without_auth:
            raise

        # We allow people to not be authed if they're just looking at our
        # room list, but require auth when we proxy the request.
        # In both cases we call the auth function, as that has the side
        # effect of logging who issued this request if an access token was
        # provided.
        if server:
            raise e
        else:
            pass

    limit = parse_integer(request, "limit", 0)
    since_token = parse_string(request, "since", None)

    if limit == 0:
        # zero is a special value which corresponds to no limit.
        limit = None

    handler = self.hs.get_room_list_handler()
    if server:
        data = await handler.get_remote_public_room_list(
            server, limit=limit, since_token=since_token
        )
    else:
        data = await handler.get_local_public_room_list(
            limit=limit, since_token=since_token
        )

    return 200, data


# Traceback (AttributeError)
2019-11-04 19:52:26,074 - synapse.http.server - 109 - ERROR - POST-705775- Failed handle request via 'PublicRoomListRestServlet': <XForwardedForRequest at 0x80e5ef048 method='POST' uri='/_matrix/client/r0/publicRooms?server=domain.tld&amp;access_token=<redacted>' clientproto='HTTP/1.1' site=8008>
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/synapse/http/server.py", line 77, in wrapped_request_handler
await h(self, request)
File "/usr/local/lib/python3.6/site-packages/synapse/http/server.py", line 326, in _async_render
callback_return = await callback_return
File "/usr/local/lib/python3.6/site-packages/synapse/rest/client/v1/room.py", line 417, in on_POST
third_party_instance_id=third_party_instance_id,
File "/usr/local/lib/python3.6/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
result = g.send(result)
File "/usr/local/lib/python3.6/site-packages/synapse/handlers/room_list.py", line 391, in get_remote_public_room_list
third_party_instance_id=third_party_instance_id,
File "/usr/local/lib/python3.6/site-packages/synapse/handlers/room_list.py", line 441, in _get_remote_list_cached
third_party_instance_id=third_party_instance_id,
File "/usr/local/lib/python3.6/site-packages/synapse/util/caches/response_cache.py", line 151, in wrap
result = self.set(key, d)
File "/usr/local/lib/python3.6/site-packages/synapse/util/caches/response_cache.py", line 95, in set
result = ObservableDeferred(deferred, consumeErrors=True)
File "/usr/local/lib/python3.6/site-packages/synapse/util/async_helpers.py", line 87, in __init__
deferred.addCallbacks(callback, errback)
AttributeError: 'NoneType' object has no attribute 'addCallbacks'

# Fixed code
async def on_GET(self, request):
    server = parse_string(request, "server", default=None)

    try:
        await self.auth.get_user_by_req(request, allow_guest=True)
    except InvalidClientCredentialsError as e:
        # Option to allow servers to require auth when accessing
        # /publicRooms via CS API. This is especially helpful in private
        # federations.
        if not self.hs.config.allow_public_rooms_without_auth:
            raise

        # We allow people to not be authed if they're just looking at our
        # room list, but require auth when we proxy the request.
        # In both cases we call the auth function, as that has the side
        # effect of logging who issued this request if an access token was
        # provided.
        if server:
            raise e
        else:
            pass

    limit = parse_integer(request, "limit", 0)
    since_token = parse_string(request, "since", None)

    if limit == 0:
        # zero is a special value which corresponds to no limit.
        limit = None

    handler = self.hs.get_room_list_handler()
    if server and server != self.hs.config.server_name:
        try:
            data = await handler.get_remote_public_room_list(
                server, limit=limit, since_token=since_token
            )
        except HttpResponseException as e:
            raise e.to_synapse_error()
    else:
        data = await handler.get_local_public_room_list(
            limit=limit, since_token=since_token
        )

    return 200, data