Accessing response status

16 views
Skip to first unread message

Scot Hacker

unread,
Nov 7, 2011, 8:45:20 PM11/7/11
to google-visua...@googlegroups.com
Sorry for the newbie question, but I've been banging my head against this for quite a while. 

In the dummy code below, there are three functions - two that are "required" by the Visualization API and one RunMe() that kicks it off. If a spreadsheet request is invalid, I can access the error message it returns from the handleQueryResponse() function. But for my purposes, I need to be able to test for the existence of response.isError() from within the runMe() function. This seems simple, but I can't seem to get at that response object from outside of handleQueryResponse(). This may be due to my JavaScript newbie status or because the API does something weird.

I also find it weird that uncommenting console.log(query); in the getTableMeta() function produces an "Er" object that just seems to be a prototype, not a representation of the actual query.

Thanks for suggestions.

The spreadsheet ID below is invalid with the "z" at the end and valid with it removed.

function runMe() {
    var foo = getTableMeta('0AtP_YtDJ532RdDcxZUl6Zkl4YkxKcEYzbld4ZDA4SlEz');
    // console.log(response);
    // console.log(response.getMessage());
    // console.log(foo.getMessage());
}  


// Get table metadata from Google
function getTableMeta(spreadsheet_id) {

    var query = new google.visualization.Query('https://spreadsheets.google.com/a/google.com/tq?key=' + spreadsheet_id);
    // console.log(query);
    query.send(handleQueryResponse); 
    }       


function handleQueryResponse(response) {
    if (response.isError()) {
        // alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage() + '. Please click Previous and enter a different spreadsheet ID.');
        console.log(response.getMessage());
    }    
    return response;
}   

runMe();

Roni Biran

unread,
Nov 8, 2011, 1:33:16 AM11/8/11
to google-visua...@googlegroups.com
Hi Scot,

The reason why you can't access the response from within the Rue function is that it does not exist yet. The response is generated by the query function that passes is via asyc process to the handle function. If it was a sync process your request was doable.
As for your "Er" object, the google code is minified, thus all objects and variables have non meaningful names :-)

Hope that this help a little to understand your position.

Let me know if there's something else I can do to help


--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-visualization-api/-/7N-JHH_2J0oJ.
To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.

Scot Hacker

unread,
Nov 8, 2011, 2:46:39 PM11/8/11
to google-visua...@googlegroups.com
Thanks much TheNez. This was going to be a wizard like interface, and I was hoping to access that response object in a remote function so I could validate step 1 (which would determine whether the user could move on). But I'll figure out a different way to architect it. I appreciate the response!

Roni Biran

unread,
Nov 9, 2011, 3:16:26 AM11/9/11
to google-visua...@googlegroups.com
in that case what i would do is create a mediator function that will decide on the validation of the user before going on.


On Tue, Nov 8, 2011 at 9:46 PM, Scot Hacker <sha...@birdhouse.org> wrote:
Thanks much TheNez. This was going to be a wizard like interface, and I was hoping to access that response object in a remote function so I could validate step 1 (which would determine whether the user could move on). But I'll figure out a different way to architect it. I appreciate the response!

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
Reply all
Reply to author
Forward
0 new messages