Skip to content

Commit

Permalink
Merge pull request #3725 from NoelDeMartin/MOBILE-4341
Browse files Browse the repository at this point in the history
MOBILE-4341 core: Ignore native error codes in web
  • Loading branch information
jleyva authored Jul 6, 2023
2 parents 26147e8 + 844d039 commit 670bb10
Showing 1 changed file with 52 additions and 43 deletions.
95 changes: 52 additions & 43 deletions src/core/services/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,51 +512,60 @@ export class CoreWSProvider {
supportConfig: await CoreUserGuestSupportConfig.forSite(preSets.siteUrl),
};

switch (data.status) {
case NativeHttp.ErrorCode.SSL_EXCEPTION:
options.errorcode = 'invalidcertificate';
options.errorDetails = Translate.instant('core.certificaterror', {
details: CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Invalid certificate',
});
break;
case NativeHttp.ErrorCode.SERVER_NOT_FOUND:
options.errorcode = 'servernotfound';
options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Server could not be found';
break;
case NativeHttp.ErrorCode.TIMEOUT:
options.errorcode = 'requesttimeout';
options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Request timed out';
break;
case NativeHttp.ErrorCode.UNSUPPORTED_URL:
options.errorcode = 'unsupportedurl';
options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Url not supported';
break;
case NativeHttp.ErrorCode.NOT_CONNECTED:
options.errorcode = 'connectionerror';
options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error)
?? 'Connection error, is network available?';
break;
case NativeHttp.ErrorCode.ABORTED:
options.errorcode = 'requestaborted';
options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Request aborted';
break;
case NativeHttp.ErrorCode.POST_PROCESSING_FAILED:
options.errorcode = 'requestprocessingfailed';
options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Request processing failed';
break;
case 404:
options.errorcode = 'endpointnotfound';
options.errorDetails = Translate.instant('core.ajaxendpointnotfound', { $a: CoreSite.MINIMUM_MOODLE_VERSION });
break;
default: {
const details = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Unknown error';
if (CorePlatform.isMobile()) {
switch (data.status) {
case NativeHttp.ErrorCode.SSL_EXCEPTION:
options.errorcode = 'invalidcertificate';
options.errorDetails = Translate.instant('core.certificaterror', {
details: CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Invalid certificate',
});
break;
case NativeHttp.ErrorCode.SERVER_NOT_FOUND:
options.errorcode = 'servernotfound';
options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Server could not be found';
break;
case NativeHttp.ErrorCode.TIMEOUT:
options.errorcode = 'requesttimeout';
options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Request timed out';
break;
case NativeHttp.ErrorCode.UNSUPPORTED_URL:
options.errorcode = 'unsupportedurl';
options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Url not supported';
break;
case NativeHttp.ErrorCode.NOT_CONNECTED:
options.errorcode = 'connectionerror';
options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error)
?? 'Connection error, is network available?';
break;
case NativeHttp.ErrorCode.ABORTED:
options.errorcode = 'requestaborted';
options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Request aborted';
break;
case NativeHttp.ErrorCode.POST_PROCESSING_FAILED:
options.errorcode = 'requestprocessingfailed';
options.errorDetails = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Request processing failed';
break;
}
}

options.errorcode = 'serverconnectionajax';
options.errorDetails = Translate.instant('core.serverconnection', {
details: `[Response status code: ${data.status}] ${details}`,
});
if (!options.errorcode) {
switch (data.status) {
case 404:
options.errorcode = 'endpointnotfound';
options.errorDetails = Translate.instant('core.ajaxendpointnotfound', {
$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);
Expand Down

0 comments on commit 670bb10

Please sign in to comment.