MOBILE-4047 errors: Admit buttons when creating a CoreError
parent
c1cae77bbc
commit
7dfcd8bfe3
|
@ -23,7 +23,7 @@ import { CoreAjaxWSError } from './ajaxwserror';
|
|||
import { CoreCaptureError } from './captureerror';
|
||||
import { CoreNetworkError } from './network-error';
|
||||
import { CoreSiteError } from './siteerror';
|
||||
import { CoreErrorWithTitle } from './errorwithtitle';
|
||||
import { CoreErrorWithOptions } from './errorwithtitle';
|
||||
import { CoreHttpError } from './httperror';
|
||||
|
||||
export const CORE_ERRORS_CLASSES: Type<unknown>[] = [
|
||||
|
@ -36,6 +36,6 @@ export const CORE_ERRORS_CLASSES: Type<unknown>[] = [
|
|||
CoreSilentError,
|
||||
CoreSiteError,
|
||||
CoreWSError,
|
||||
CoreErrorWithTitle,
|
||||
CoreErrorWithOptions,
|
||||
CoreHttpError,
|
||||
];
|
||||
|
|
|
@ -12,20 +12,24 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { AlertButton } from '@ionic/angular';
|
||||
import { CoreError } from './error';
|
||||
|
||||
/**
|
||||
* Error with an explicit title describing the problem (instead of just "Error" or a generic message).
|
||||
* This title should be used to communicate the problem with users, and if it's undefined it should be omitted.
|
||||
* The error also may contain customizable action buttons.
|
||||
*/
|
||||
export class CoreErrorWithTitle extends CoreError {
|
||||
export class CoreErrorWithOptions extends CoreError {
|
||||
|
||||
title?: string;
|
||||
buttons?: AlertButton[];
|
||||
|
||||
constructor(message?: string, title?: string) {
|
||||
constructor(message?: string, title?: string, buttons?: AlertButton[]) {
|
||||
super(message);
|
||||
|
||||
this.title = title;
|
||||
this.buttons = buttons;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ import { CoreRedirectPayload } from './navigator';
|
|||
import { CoreSitesFactory } from './sites-factory';
|
||||
import { CoreText } from '@singletons/text';
|
||||
import { CoreLoginHelper } from '@features/login/services/login-helper';
|
||||
import { CoreErrorWithTitle } from '@classes/errors/errorwithtitle';
|
||||
import { CoreErrorWithOptions } from '@classes/errors/errorwithtitle';
|
||||
import { CoreAjaxError } from '@classes/errors/ajaxerror';
|
||||
import { CoreAjaxWSError } from '@classes/errors/ajaxwserror';
|
||||
import { CoreSitePlugins } from '@features/siteplugins/services/siteplugins';
|
||||
|
@ -870,7 +870,7 @@ export class CoreSitesProvider {
|
|||
|
||||
const siteUrlAllowed = await CoreLoginHelper.isSiteUrlAllowed(site.getURL(), false);
|
||||
if (!siteUrlAllowed) {
|
||||
throw new CoreErrorWithTitle(Translate.instant('core.login.sitenotallowed'));
|
||||
throw new CoreErrorWithOptions(Translate.instant('core.login.sitenotallowed'));
|
||||
}
|
||||
|
||||
this.currentSite = site;
|
||||
|
|
|
@ -1344,7 +1344,6 @@ export class CoreDomUtilsProvider {
|
|||
|
||||
const alertOptions: AlertOptions = {
|
||||
message: message,
|
||||
buttons: [Translate.instant('core.ok')],
|
||||
};
|
||||
|
||||
if (this.isNetworkError(message, error)) {
|
||||
|
@ -1355,6 +1354,12 @@ export class CoreDomUtilsProvider {
|
|||
alertOptions.header = Translate.instant('core.error');
|
||||
}
|
||||
|
||||
if (typeof error !== 'string' && 'buttons' in error && typeof error.buttons !== 'undefined') {
|
||||
alertOptions.buttons = error.buttons;
|
||||
} else {
|
||||
alertOptions.buttons = [Translate.instant('core.ok')];
|
||||
}
|
||||
|
||||
return this.showAlertWithOptions(alertOptions, autocloseTime);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import { CoreFileHelper } from '@services/file-helper';
|
|||
import { CoreDomUtils } from './dom';
|
||||
import { CoreText } from '@singletons/text';
|
||||
import { CoreUrl } from '@singletons/url';
|
||||
import { AlertButton } from '@ionic/angular';
|
||||
|
||||
/**
|
||||
* Different type of errors the app can treat.
|
||||
|
@ -38,6 +39,7 @@ export type CoreTextErrorObject = {
|
|||
debuginfo?: string;
|
||||
backtrace?: string;
|
||||
title?: string;
|
||||
buttons?: AlertButton[];
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -166,7 +168,7 @@ export class CoreTextUtilsProvider {
|
|||
improvedError = error;
|
||||
}
|
||||
|
||||
improvedError.title = title;
|
||||
improvedError.title = improvedError.title || title;
|
||||
|
||||
return improvedError;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue