I find it easy to use the error codes available in open social specification.Use this sample gadget for testing purposes.In the specification http://code.google.com/apis/opensocial/docs/0.8/reference/#opensocial.ResponseItem.getErrorCode
it says like to get error code from getErrorCode function. Its returning an enumeration.So its easy to get error codes from Error class.I tried for response.getErrorCode().. hopeless .. its undefined while response.hadError() was working !! I think spec document should be clear with examples ...mmm try the code ..
<script type="text/javascript" >
function getData() {
var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest('VIEWER'), 'viewer');
req.send(callback);
}
function callback(response){
if(!response.hadError()){
alert("Success");
var html = "Test OK"
document.getElementById('message').innerHTML = html;
}else {
alert(response.getErrorMessage());
var viewer_resp_item = response.get('viewer')
switch(viewerresp.getErrorCode())
{
case opensocial.ResponseItem.Error.INTERNAL_ERROR :
/*The request encountered an unexpected condition that prevented it from fulfilling the request*/
alert('There was an error on the server.');
break;
case opensocial.ResponseItem.Error.UNAUTHORIZED :
/*The gadget does not have access to the requested data.*/
alert('There was a permissions issue: the app is not allowed to show the data.');
break;
case opensocial.ResponseItem.Error.BAD_REQUEST :
/*The request was invalid.Parameters are wrong etc.*/
alert('There was an error in the Container.');
break;
case opensocial.ResponseItem.Error.FORBIDDEN :
/*The gadget can never have access to the requested data.*/
alert('The Container was unable to contact the server.');
break;
case opensocial.ResponseItem.Error.NOT_IMPLEMENTED :
/*This container does not support the request that was made.
Different version of implementations*/
alert('did not implement this particular OpenSocial interface.');
break;
case opensocial.ResponseItem.Error.LIMIT_EXCEEDED :
/*The gadget exceeded a quota on the request.*/
alert('Limit exceeded.');
break;
}
}
}
gadgets.util.registerOnLoadHandler(getData);
</script>
No comments:
Post a Comment