MOBILE-4059 core: Contact support from errors

main
Noel De Martin 2022-10-06 15:44:13 +02:00
parent 23341a7436
commit c34db4dcaf
3 changed files with 70 additions and 26 deletions

View File

@ -1697,6 +1697,10 @@ export class CoreSite {
*/ */
async getPublicConfig(options: { readingStrategy?: CoreSitesReadingStrategy } = {}): Promise<CoreSitePublicConfigResponse> { async getPublicConfig(options: { readingStrategy?: CoreSitesReadingStrategy } = {}): Promise<CoreSitePublicConfigResponse> {
if (!this.db) { if (!this.db) {
if (options.readingStrategy === CoreSitesReadingStrategy.ONLY_CACHE) {
throw new CoreError('Cache not available to read public config');
}
return this.requestPublicConfig(); return this.requestPublicConfig();
} }

View File

@ -34,7 +34,7 @@ import {
} from '@classes/site'; } from '@classes/site';
import { SQLiteDB, SQLiteDBRecordValues, SQLiteDBTableSchema } from '@classes/sqlitedb'; import { SQLiteDB, SQLiteDBRecordValues, SQLiteDBTableSchema } from '@classes/sqlitedb';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { CoreLoginError } from '@classes/errors/loginerror'; import { CoreLoginError, CoreLoginErrorOptions } from '@classes/errors/loginerror';
import { makeSingleton, Translate, Http } from '@singletons'; import { makeSingleton, Translate, Http } from '@singletons';
import { CoreLogger } from '@singletons/logger'; import { CoreLogger } from '@singletons/logger';
import { import {
@ -296,17 +296,19 @@ export class CoreSitesProvider {
// Check that the user can authenticate. // Check that the user can authenticate.
if (!config.enablewebservices) { if (!config.enablewebservices) {
throw this.createCannotConnectError( throw this.createCannotConnectError({
'webservicesnotenabled', errorcode: 'webservicesnotenabled',
Translate.instant('core.login.webservicesnotenabled'), errorDetails: Translate.instant('core.login.webservicesnotenabled'),
config, siteConfig: config,
); critical: true,
});
} else if (!config.enablemobilewebservice) { } else if (!config.enablemobilewebservice) {
throw this.createCannotConnectError( throw this.createCannotConnectError({
'mobileservicesnotenabled', errorcode: 'mobileservicesnotenabled',
Translate.instant('core.login.mobileservicesnotenabled'), errorDetails: Translate.instant('core.login.mobileservicesnotenabled'),
config, siteConfig: config,
); critical: true,
});
} else if (config.maintenanceenabled) { } else if (config.maintenanceenabled) {
let message = Translate.instant('core.sitemaintenance'); let message = Translate.instant('core.sitemaintenance');
if (config.maintenancemessage) { if (config.maintenancemessage) {
@ -327,23 +329,14 @@ export class CoreSitesProvider {
/** /**
* Create an error to be thrown when it isn't possible to connect to a site. * Create an error to be thrown when it isn't possible to connect to a site.
* *
* @param errorcode Error code. * @param options Error options.
* @param errorDetails Error details.
* @param siteConfig Site config.
* @return Cannot connect error. * @return Cannot connect error.
*/ */
protected createCannotConnectError( protected createCannotConnectError(options: Partial<CoreLoginErrorOptions> = {}): CoreLoginError {
errorcode: string,
errorDetails: string,
siteConfig: CoreSitePublicConfigResponse,
): CoreLoginError {
return new CoreLoginError({ return new CoreLoginError({
errorcode, ...options,
errorDetails,
siteConfig,
message: Translate.instant('core.cannotconnecttrouble'), message: Translate.instant('core.cannotconnecttrouble'),
fallbackMessage: Translate.instant('core.cannotconnecttroublewithoutsupport'), fallbackMessage: Translate.instant('core.cannotconnecttroublewithoutsupport'),
critical: true,
contactSupport: true, contactSupport: true,
}); });
} }
@ -433,9 +426,12 @@ export class CoreSitesProvider {
} }
if (data.error && data.error == 'Web services must be enabled in Advanced features.') { if (data.error && data.error == 'Web services must be enabled in Advanced features.') {
throw new CoreLoginError({ const siteConfig = await CoreUtils.ignoreErrors(this.getPublicSiteConfigByUrl(siteUrl));
throw this.createCannotConnectError({
errorcode: 'enablewsdescription', errorcode: 'enablewsdescription',
message: data.error, errorDetails: data.error,
siteConfig,
}); });
} }
@ -1110,6 +1106,18 @@ export class CoreSitesProvider {
return this.addSiteFromSiteListEntry(data); return this.addSiteFromSiteListEntry(data);
} }
/**
* Gets the public type config for a site with the given url.
*
* @param siteUrl The site URL.
* @return Promise resolved with public config or null.
*/
async getPublicSiteConfigByUrl(siteUrl: string): Promise<CoreSitePublicConfigResponse> {
const site = await this.getSiteByUrl(siteUrl);
return site.getPublicConfig({ readingStrategy: CoreSitesReadingStrategy.ONLY_CACHE });
}
/** /**
* Create a site from an entry of the sites list DB. The new site is added to the list of "cached" sites: this.sites. * Create a site from an entry of the sites list DB. The new site is added to the list of "cached" sites: this.sites.
* *

View File

@ -54,6 +54,9 @@ import { Subscription } from 'rxjs';
import { CoreComponentsRegistry } from '@singletons/components-registry'; import { CoreComponentsRegistry } from '@singletons/components-registry';
import { CoreDom } from '@singletons/dom'; import { CoreDom } from '@singletons/dom';
import { CoreNetwork } from '@services/network'; import { CoreNetwork } from '@services/network';
import { CoreSiteError } from '@classes/errors/siteerror';
import { CoreUserSupport } from '@features/user/services/support';
import { CoreErrorInfoComponent } from '@components/error-info/error-info';
/* /*
* "Utils" service with helper functions for UI, DOM elements and HTML code. * "Utils" service with helper functions for UI, DOM elements and HTML code.
@ -1356,11 +1359,40 @@ export class CoreDomUtilsProvider {
if (typeof error !== 'string' && 'buttons' in error && typeof error.buttons !== 'undefined') { if (typeof error !== 'string' && 'buttons' in error && typeof error.buttons !== 'undefined') {
alertOptions.buttons = error.buttons; alertOptions.buttons = error.buttons;
} else if (error instanceof CoreSiteError) {
alertOptions.buttons = [];
if (error.errorDetails) {
alertOptions.message += '<div class="core-error-info-container"></div>';
}
if (error.canContactSupport()) {
alertOptions.buttons.push({
text: Translate.instant('core.contactsupport'),
handler: () => CoreUserSupport.contact({
supportPageUrl: error.getSupportPageUrl(),
subject: alertOptions.header,
message: `${error.errorcode}\n\n${error.errorDetails}`,
}),
});
}
alertOptions.buttons.push(Translate.instant('core.ok'));
} else { } else {
alertOptions.buttons = [Translate.instant('core.ok')]; alertOptions.buttons = [Translate.instant('core.ok')];
} }
return this.showAlertWithOptions(alertOptions, autocloseTime); const alertElement = await this.showAlertWithOptions(alertOptions, autocloseTime);
if (error instanceof CoreSiteError && error.errorDetails) {
const containerElement = alertElement.querySelector('.core-error-info-container');
if (containerElement) {
containerElement.innerHTML = CoreErrorInfoComponent.render(error.errorDetails, error.errorcode);
}
}
return alertElement;
} }
/** /**