Access http body on Dojo request error

http://stackoverflow.com/questions/12483149/access-http-body-on-dojo-request-error

by phusick

HTML

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.7.2/dijit/themes/claro/claro.css">

CSS

body {
    padding: 30px;
}

JavaScript

require([
    "dojo/request/xhr"
], function(
    request
) {

    var promise = request.get("/echo/jsonx", {
        handleAs: "json",
        preventCache: true,
        timestamp: (new Date()).valueOf()
    });
    
    promise.response.then(function(response) {
        console.log("status", response.status);
        console.log("options", response.options);
        console.log("url", response.url);
        console.log("timestamp", response.options.timestamp);
        
        console.log(response);
    }, function(error) {
        console.log(error);
        console.log("http body:", error.response.text);        
    });
    
});