From 1f8cbcdb74aec9463a51a41f8deeb03d8a66183c Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Wed, 7 Jun 2023 14:42:24 +0200 Subject: [PATCH] MOBILE-4341 core: Improve http error logs --- src/core/services/ws.ts | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/core/services/ws.ts b/src/core/services/ws.ts index ecd18e939..5b2c7b3d5 100644 --- a/src/core/services/ws.ts +++ b/src/core/services/ws.ts @@ -506,21 +506,49 @@ export class CoreWSProvider { }; switch (data.status) { - case -2: // Certificate error. + case NativeHttp.ErrorCode.SSL_EXCEPTION: options.errorcode = 'invalidcertificate'; options.errorDetails = Translate.instant('core.certificaterror', { - details: CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Unknown error', + details: CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Invalid certificate', }); break; - case 404: // AJAX endpoint not found. + 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: + default: { + const details = CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Unknown error'; + options.errorcode = 'serverconnectionajax'; options.errorDetails = Translate.instant('core.serverconnection', { - details: CoreTextUtils.getErrorMessageFromError(data.error) ?? 'Unknown error', + details: `[Response status code: ${data.status}] ${details}`, }); + } break; }