request.then(reqSucceeded, reqFailed) wrong function being called when error

Discussion created by krisww on Apr 15, 2014

first of all I'm new to ArcGIS Javascript API. I have the following code:

    var request = new esri.request({
        url: mapServerUrl,
        content: { "f": "json" },
        timeout: 0,
        handleAs: "text",
        options: {
            useProxy: true

    request.then(reqSucceeded, reqFailed);

I modify mapServerUrl parameter by giving it either a invalid or valid url. When an invalid url is given the reqSucceeded function fires. Inspecting the response object I see the below string which is valid but why is the reqSucceeded function being called when there clearly was an error? 

"{\"error\":{\"code\":400,\"message\":\"Invalid URL\",\"details\":[]}}"