@nettyapps/ntybase 21.1.30 → 21.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -377,67 +377,42 @@ class AlertService {
|
|
|
377
377
|
verticalPosition: 'bottom',
|
|
378
378
|
});
|
|
379
379
|
}
|
|
380
|
-
// For error notifications
|
|
381
380
|
/**
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
else if (typeof fallbackOrComponent === 'function') {
|
|
396
|
-
// showError(err, MySpecialComponent)
|
|
397
|
-
componentToOpen = fallbackOrComponent;
|
|
398
|
-
}
|
|
399
|
-
// Extract Message (C# / Backend message has priority)
|
|
400
|
-
const backendError = this.getErrorMessage(error);
|
|
401
|
-
// Final Message Decision: Use backend message if exists, otherwise translate fallback key
|
|
402
|
-
const finalMessage = (backendError && backendError !== JSON.stringify(error))
|
|
403
|
-
? backendError
|
|
404
|
-
: (fallbackMsg ? this.translate.instant(fallbackMsg) : backendError);
|
|
381
|
+
* Displays an error dialog with flexible parameters.
|
|
382
|
+
* Intelligently extracts meaningful C# error messages or falls back to a translation key.
|
|
383
|
+
* * Supported usages:
|
|
384
|
+
* - showError('@fallbackKey', err)
|
|
385
|
+
* - showError(err)
|
|
386
|
+
* - showError(err, '@fallbackKey')
|
|
387
|
+
* - showError('@fallbackKey')
|
|
388
|
+
*/
|
|
389
|
+
showError(arg1, arg2, customComponent = ErrorAlert, width = 'auto', height = 'auto') {
|
|
390
|
+
const isArg1Str = typeof arg1 === 'string';
|
|
391
|
+
const fallbackKey = isArg1Str ? arg1 : (typeof arg2 === 'string' ? arg2 : '');
|
|
392
|
+
const errorObj = isArg1Str ? arg2 : arg1;
|
|
393
|
+
// Open the Dialog
|
|
405
394
|
return new Promise((resolve) => {
|
|
406
|
-
|
|
407
|
-
width:
|
|
408
|
-
height: height,
|
|
409
|
-
maxWidth: '95vw',
|
|
395
|
+
this.dialog.open(customComponent, {
|
|
396
|
+
width, height, maxWidth: '95vw',
|
|
410
397
|
data: {
|
|
411
|
-
message:
|
|
398
|
+
message: this.getErrorMessage(errorObj, fallbackKey),
|
|
412
399
|
title: this.translate.instant('@errorOccurred'),
|
|
413
400
|
},
|
|
414
|
-
});
|
|
415
|
-
dialogRef.afterClosed().subscribe(() => {
|
|
416
|
-
resolve();
|
|
417
|
-
});
|
|
401
|
+
}).afterClosed().subscribe(() => resolve());
|
|
418
402
|
});
|
|
419
403
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
return error.details;
|
|
433
|
-
if (error?.message && typeof error.message === 'string' && !error.message.startsWith('@'))
|
|
434
|
-
return error.message;
|
|
435
|
-
/// 2. Localization Keys (starting with @)
|
|
436
|
-
if (typeof error === 'string' && error.startsWith('@'))
|
|
437
|
-
return this.translate.instant(error);
|
|
438
|
-
if (error?.message && typeof error.message === 'string' && error.message.startsWith('@'))
|
|
439
|
-
return this.translate.instant(error.message);
|
|
440
|
-
return typeof error === 'string' ? error : JSON.stringify(error);
|
|
404
|
+
getErrorMessage(errorObj, fallbackKey) {
|
|
405
|
+
if (!errorObj) {
|
|
406
|
+
return fallbackKey ? this.translate.instant(fallbackKey) : this.translate.instant('@errorOccurred');
|
|
407
|
+
}
|
|
408
|
+
const data = errorObj.error ?? errorObj;
|
|
409
|
+
const isStr = typeof data === 'string';
|
|
410
|
+
const backendMessage = isStr ? data : (data?.message || data?.details || JSON.stringify(data));
|
|
411
|
+
const isMeaningful = isStr ? !data.startsWith('<') : !!(data?.message || data?.details);
|
|
412
|
+
if (fallbackKey) {
|
|
413
|
+
return isMeaningful ? backendMessage : this.translate.instant(fallbackKey);
|
|
414
|
+
}
|
|
415
|
+
return backendMessage;
|
|
441
416
|
}
|
|
442
417
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: AlertService, deps: [{ token: i1$2.MatSnackBar }, { token: i1.MatDialog }, { token: i1$1.TranslateService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
443
418
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: AlertService, providedIn: 'root' });
|