import requests
import json


def mock_ws_bad(rqm, msg):
    """
    Always returns a 500 from a workspace call, triggering a ServerError
    """
    def mock_adapter_bad_ws(request):
        response = requests.Response()
        response.status_code = 500
        response._content = bytes(json.dumps({
            "error": {
                "code": -32500,
                "message": msg,
                "error": "long Java vomit stacktrace",
                "name": "JSONRPCError"
            },
            "version": "1.1",
            "id": request.json().get("id", "12345")
        }), "UTF-8")
        return response
    rqm.add_matcher(mock_adapter_bad_ws)