MOBILE-4059 core: Contact support from ajax errors
parent
c34db4dcaf
commit
dca3f76296
|
@ -12,18 +12,18 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { CoreError } from '@classes/errors/error';
|
import { CoreSiteError, CoreSiteErrorOptions } from '@classes/errors/siteerror';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic error returned by an Ajax call.
|
* Generic error returned by an Ajax call.
|
||||||
*/
|
*/
|
||||||
export class CoreAjaxError extends CoreError {
|
export class CoreAjaxError extends CoreSiteError {
|
||||||
|
|
||||||
available = 1; // @deprecated since app 4.0. AJAX endpoint should always be available in supported Moodle versions.
|
available = 1; // @deprecated since app 4.0. AJAX endpoint should always be available in supported Moodle versions.
|
||||||
status?: number;
|
status?: number;
|
||||||
|
|
||||||
constructor(message: string, available?: number, status?: number) {
|
constructor(messageOrOptions: string | CoreSiteErrorOptions, available?: number, status?: number) {
|
||||||
super(message);
|
super(typeof messageOrOptions === 'string' ? { message: messageOrOptions } : messageOrOptions);
|
||||||
|
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,8 @@ import { CoreSite } from '@classes/site';
|
||||||
import { CoreHttpError } from '@classes/errors/httperror';
|
import { CoreHttpError } from '@classes/errors/httperror';
|
||||||
import { CorePromisedValue } from '@classes/promised-value';
|
import { CorePromisedValue } from '@classes/promised-value';
|
||||||
import { CorePlatform } from '@services/platform';
|
import { CorePlatform } from '@services/platform';
|
||||||
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
|
import { CoreSites } from '@services/sites';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This service allows performing WS calls and download/upload files.
|
* This service allows performing WS calls and download/upload files.
|
||||||
|
@ -456,7 +458,7 @@ export class CoreWSProvider {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return promise.then((response) => {
|
return promise.then(async (response) => {
|
||||||
let data = response.body;
|
let data = response.body;
|
||||||
|
|
||||||
// Some moodle web services return null.
|
// Some moodle web services return null.
|
||||||
|
@ -467,7 +469,16 @@ export class CoreWSProvider {
|
||||||
|
|
||||||
// Check if error. Ajax layer should always return an object (if error) or an array (if success).
|
// Check if error. Ajax layer should always return an object (if error) or an array (if success).
|
||||||
if (!data || typeof data != 'object') {
|
if (!data || typeof data != 'object') {
|
||||||
throw new CoreAjaxError(Translate.instant('core.serverconnection'));
|
const siteConfig = await CoreUtils.ignoreErrors(CoreSites.getPublicSiteConfigByUrl(preSets.siteUrl));
|
||||||
|
|
||||||
|
throw new CoreAjaxError({
|
||||||
|
siteConfig,
|
||||||
|
contactSupport: true,
|
||||||
|
message: Translate.instant('core.cannotconnecttrouble'),
|
||||||
|
fallbackMessage: Translate.instant('core.cannotconnecttroublewithoutsupport'),
|
||||||
|
errorcode: 'invalidresponse',
|
||||||
|
errorDetails: Translate.instant('core.serverconnection'),
|
||||||
|
});
|
||||||
} else if (data.error) {
|
} else if (data.error) {
|
||||||
throw new CoreAjaxWSError(data);
|
throw new CoreAjaxWSError(data);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue