Open luxio opened 7 years ago
@luxio The latest dev snapshot of jdrupal.min.js
(I really need to release another recommended release soon) has some big time improvements to error
handling when using jDrupal's Service Resource layer.
When attaching a typical error
handler to a service resource call in DrupalGap, that error
handler is now being hit when some odd networking errors occur. I don't recall is I've come across the ERR_NAME_NOT_RESOLVED
response before, but you can see here in jDrupal where I was able to add coverage for strange networking issues:
https://github.com/signalpoint/jDrupal/blob/7.x-1.x/src/services/services.js#L35
So as long as your call to services/session/token
is running through the jDrupal Services layer, you should be able to catch that error, for example:
services_get_csrf_token({
success: function(token) { alert('Got the token' + token); },
error: function(xhr, status, msg) {
// Something went wrong...
console.log(arguments);
alert(msg);
}
});
The status
and xhr
values should both contain good debugging info that you can then relay to the user in the error
handler.
@signalpoint Thank you for the info. I will definitely check it out.
Meanwhile I have resolved this by checking for a file on the server:
function mymodule_user_login_submit_check_site_path(form, form_state) {
try {
// check if server can be reached
var xhr = new XMLHttpRequest();
var submitted_sitepath = 'https://' + form_state.values.mymodule_site_path;
var file = submitted_sitepath+'/files/test.gif';
var randomNum = Math.round(Math.random() * 10000);
xhr.open('HEAD', file + "?rand=" + randomNum, true);
xhr.send();
xhr.addEventListener("readystatechange", processRequest, false);
function processRequest(e) {
if (xhr.readyState == 4) {
if (xhr.status >= 200 && xhr.status < 304) {
// can connect to server
mymodule_user_login_submit(form, form_state);
} else {
var msg = t('Failed to connect to') + ' ' + submitted_sitepath + ' ' +
t('Please check the site name.');
drupalgap_alert(msg, {
title: t('Connection Failure'),
buttonName: t('OK'),
});
}
}
}
} catch (error) {
console.log('mymodule_user_login_submit_check_site_path - ' + error);
}
}
In my app,
Drupal.settings.site_path
can be configured by the user.Is there a way, to check, if the Drupal.settings.site_path can be resolved? If the server cannot be resolved I want to go back to login form (where the user can edit the
Drupal.settings.site_path
and try again).If the user enters a non existing host, DG freezes. On iOS I don't get an error in the console.
Using ripple, I get this error if the the host cannot be resolved:
Or if the server is in maintenance mode: