Opened 7 years ago

Closed 4 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 7 years ago by bill

Component: GeneralIO
Owner: set to Bryan Forbes

comment:2 Changed 7 years ago by Fausto Lemos

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...

comment:3 Changed 7 years ago by bill

Same problem as #16345. Sounds like this should really be documented better.

comment:4 Changed 4 years ago by dylan

Component: IODocumentation
Milestone: tbd1.11
Owner: changed from Bryan Forbes to dylan
Status: newassigned

comment:5 Changed 4 years ago by dylan

Resolution: fixed
Status: assignedclosed

Updated the prose in the blog post to make this clearer hopefully.

Note: See TracTickets for help on using tickets.