Opened 9 years ago
Closed 7 years ago
#16666 closed defect (fixed)
promise.response error callback
Reported by: | Fausto Lemos | Owned by: | dylan |
---|---|---|---|
Priority: | undecided | Milestone: | 1.11 |
Component: | Documentation | Version: | 1.8.1 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
hi,
i'm facing a strage problem when i use promise.response.then() to get response data.
When my request goes ok (status 200) and success callback is invoked i can read response status, response data and etc...
But when things go wrong (like code 401 for an unauthorized access) my callback error is invoked but the response is not a object with properties like mentioned above.. it's a string (i.e "Request error http://... status:401" Code:
var promise = request("some/url", {handleAs:"json"});
promise.response.then(
function(responseSuccess) {
console.log(responseSuccess.status); prints 200
},
function (responseError) {
console.log(responseError.status); prints undefined because responseError its a string..
console.log(responseError) prints "Request error http://...:status:401"
}
);
if i use dojo.xhr (legacy) i can read the response perfectly...
when reading this post http://www.sitepen.com/blog/2012/08/21/introducing-dojorequest/ i don't understand when he says:
"Promises returned from dojo/request calls have an additional property not available on standard promises: response. This property is a promise that will resolve to a frozen object (where available) describing the response in more detail"
What means standard promises? how can i know if my promise is a standard promise?
anyone have a clue about why i'm not able to read my response in case of errors?
Change History (5)
comment:1 Changed 9 years ago by
Component: | General → IO |
---|---|
Owner: | set to Bryan Forbes |
comment:2 Changed 9 years ago by
comment:3 Changed 9 years ago by
Same problem as #16345. Sounds like this should really be documented better.
comment:4 Changed 7 years ago by
Component: | IO → Documentation |
---|---|
Milestone: | tbd → 1.11 |
Owner: | changed from Bryan Forbes to dylan |
Status: | new → assigned |
comment:5 Changed 7 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Updated the prose in the blog post to make this clearer hopefully.
Someone at user list solve the problem i was trying to access responseError.status instead responseError.response.status...
i just think that documentation must be improved with a more explicity example because its not clear enough that for a successfully request the callback parameter is the "response" property mentioned at documentation and for non-success request we must walk through the parameter to finally get the response...