MOBILE-4059 login: Add error details for support
parent
1a7d64a0d4
commit
238dc458fc
|
@ -22,6 +22,7 @@ import { CoreUserSupport } from '@features/user/services/support';
|
|||
export class CoreSiteError extends CoreError {
|
||||
|
||||
errorcode?: string;
|
||||
errorDetails?: string;
|
||||
critical?: boolean;
|
||||
loggedOut?: boolean;
|
||||
contactSupport?: boolean;
|
||||
|
@ -31,6 +32,7 @@ export class CoreSiteError extends CoreError {
|
|||
super(options.message);
|
||||
|
||||
this.errorcode = options.errorcode;
|
||||
this.errorDetails = options.errorDetails;
|
||||
this.critical = options.critical;
|
||||
this.loggedOut = options.loggedOut;
|
||||
this.contactSupport = options.contactSupport;
|
||||
|
@ -68,6 +70,7 @@ export class CoreSiteError extends CoreError {
|
|||
export type CoreSiteErrorOptions = {
|
||||
message: string;
|
||||
errorcode?: string;
|
||||
errorDetails?: string;
|
||||
critical?: boolean; // Whether the error is important enough to abort the operation.
|
||||
loggedOut?: boolean; // Whether site has been marked as logged out.
|
||||
contactSupport?: boolean;
|
||||
|
|
|
@ -386,10 +386,14 @@ export class CoreLoginSitePage implements OnInit {
|
|||
let errorMessage = CoreDomUtils.getErrorMessage(error);
|
||||
let siteExists = false;
|
||||
let supportPageUrl: string | null = null;
|
||||
let errorDetails: string | undefined;
|
||||
let errorCode: string | undefined;
|
||||
|
||||
if (error instanceof CoreSiteError) {
|
||||
siteExists = !!error.siteConfig;
|
||||
supportPageUrl = error.canContactSupport() ? error.getSupportPageUrl() : null;
|
||||
errorDetails = error.errorDetails;
|
||||
errorCode = error.errorcode;
|
||||
}
|
||||
|
||||
if (errorMessage == Translate.instant('core.cannotconnecttrouble')) {
|
||||
|
@ -413,6 +417,7 @@ export class CoreLoginSitePage implements OnInit {
|
|||
handler: () => CoreUserSupport.contact({
|
||||
supportPageUrl,
|
||||
subject: Translate.instant('core.cannotconnect', { $a: CoreSite.MINIMUM_MOODLE_VERSION }),
|
||||
message: `Error: ${errorCode}\n\n${errorDetails}`,
|
||||
}),
|
||||
}
|
||||
: {
|
||||
|
|
|
@ -296,19 +296,17 @@ export class CoreSitesProvider {
|
|||
|
||||
// Check that the user can authenticate.
|
||||
if (!config.enablewebservices) {
|
||||
throw new CoreSiteError({
|
||||
message: Translate.instant('core.login.webservicesnotenabled'),
|
||||
critical: true,
|
||||
contactSupport: true,
|
||||
siteConfig: config,
|
||||
});
|
||||
throw this.createCannotConnectError(
|
||||
'webservicesnotenabled',
|
||||
Translate.instant('core.login.webservicesnotenabled'),
|
||||
config,
|
||||
);
|
||||
} else if (!config.enablemobilewebservice) {
|
||||
throw new CoreSiteError({
|
||||
message: Translate.instant('core.login.mobileservicesnotenabled'),
|
||||
critical: true,
|
||||
contactSupport: true,
|
||||
siteConfig: config,
|
||||
});
|
||||
throw this.createCannotConnectError(
|
||||
'mobileservicesnotenabled',
|
||||
Translate.instant('core.login.mobileservicesnotenabled'),
|
||||
config,
|
||||
);
|
||||
} else if (config.maintenanceenabled) {
|
||||
let message = Translate.instant('core.sitemaintenance');
|
||||
if (config.maintenancemessage) {
|
||||
|
@ -326,6 +324,29 @@ export class CoreSitesProvider {
|
|||
return { siteUrl, code: config?.typeoflogin || 0, service: CoreConstants.CONFIG.wsservice, config };
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an error to be thrown when it isn't possible to connect to a site.
|
||||
*
|
||||
* @param errorcode Error code.
|
||||
* @param errorDetails Error details.
|
||||
* @param siteConfig Site config.
|
||||
* @return Cannot connect error.
|
||||
*/
|
||||
protected createCannotConnectError(
|
||||
errorcode: string,
|
||||
errorDetails: string,
|
||||
siteConfig: CoreSitePublicConfigResponse,
|
||||
): CoreSiteError {
|
||||
return new CoreSiteError({
|
||||
errorcode,
|
||||
errorDetails,
|
||||
siteConfig,
|
||||
message: Translate.instant('core.cannotconnecttrouble'),
|
||||
critical: true,
|
||||
contactSupport: true,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Treat an error returned by getPublicConfig in checkSiteWithProtocol. Converts the error to a CoreSiteError.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue