Merge pull request #3725 from NoelDeMartin/MOBILE-4341

MOBILE-4341 core: Ignore native error codes in web
main
Juan Leyva 2023-07-06 17:41:20 +02:00 committed by GitHub
commit 670bb10330
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 53 additions and 44 deletions

View File

@ -512,51 +512,60 @@ export class CoreWSProvider {
supportConfig: await CoreUserGuestSupportConfig.forSite(preSets.siteUrl), supportConfig: await CoreUserGuestSupportConfig.forSite(preSets.siteUrl),
}; };
switch (data.status) { if (CorePlatform.isMobile()) {
case NativeHttp.ErrorCode.SSL_EXCEPTION: switch (data.status) {
options.errorcode = 'invalidcertificate'; case NativeHttp.ErrorCode.SSL_EXCEPTION:
options.errorDetails = Translate.instant('core.certificaterror', { options.errorcode = 'invalidcertificate';
details: CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Invalid certificate', options.errorDetails = Translate.instant('core.certificaterror', {
}); details: CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Invalid certificate',
break; });
case NativeHttp.ErrorCode.SERVER_NOT_FOUND: break;
options.errorcode = 'servernotfound'; case NativeHttp.ErrorCode.SERVER_NOT_FOUND:
options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Server could not be found'; options.errorcode = 'servernotfound';
break; options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Server could not be found';
case NativeHttp.ErrorCode.TIMEOUT: break;
options.errorcode = 'requesttimeout'; case NativeHttp.ErrorCode.TIMEOUT:
options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Request timed out'; options.errorcode = 'requesttimeout';
break; options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Request timed out';
case NativeHttp.ErrorCode.UNSUPPORTED_URL: break;
options.errorcode = 'unsupportedurl'; case NativeHttp.ErrorCode.UNSUPPORTED_URL:
options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Url not supported'; options.errorcode = 'unsupportedurl';
break; options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Url not supported';
case NativeHttp.ErrorCode.NOT_CONNECTED: break;
options.errorcode = 'connectionerror'; case NativeHttp.ErrorCode.NOT_CONNECTED:
options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error) options.errorcode = 'connectionerror';
?? 'Connection error, is network available?'; options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error)
break; ?? 'Connection error, is network available?';
case NativeHttp.ErrorCode.ABORTED: break;
options.errorcode = 'requestaborted'; case NativeHttp.ErrorCode.ABORTED:
options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Request aborted'; options.errorcode = 'requestaborted';
break; options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Request aborted';
case NativeHttp.ErrorCode.POST_PROCESSING_FAILED: break;
options.errorcode = 'requestprocessingfailed'; case NativeHttp.ErrorCode.POST_PROCESSING_FAILED:
options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Request processing failed'; options.errorcode = 'requestprocessingfailed';
break; options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Request processing failed';
case 404: break;
options.errorcode = 'endpointnotfound'; }
options.errorDetails = Translate.instant('core.ajaxendpointnotfound', { $a: CoreSite.MINIMUM_MOODLE_VERSION }); }
break;
default: { if (!options.errorcode) {
const details = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Unknown error'; switch (data.status) {
case 404:
options.errorcode = 'serverconnectionajax'; options.errorcode = 'endpointnotfound';
options.errorDetails = Translate.instant('core.serverconnection', { options.errorDetails = Translate.instant('core.ajaxendpointnotfound', {
details: `[Response status code: ${data.status}] ${details}`, $a: CoreSite.MINIMUM_MOODLE_VERSION,
}); });
break;
default: {
const details = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Unknown error';
options.errorcode = 'serverconnectionajax';
options.errorDetails = Translate.instant('core.serverconnection', {
details: `[Response status code: ${data.status}] ${details}`,
});
}
break;
} }
break;
} }
throw new CoreAjaxError(options, 1, data.status); throw new CoreAjaxError(options, 1, data.status);