@ngx-smz/core 21.0.5 → 21.1.0
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.
|
@@ -8990,7 +8990,17 @@ class CustomError {
|
|
|
8990
8990
|
messages;
|
|
8991
8991
|
redirectTo;
|
|
8992
8992
|
static getErrorMessages(error) {
|
|
8993
|
-
const
|
|
8993
|
+
const config = GlobalInjector.config;
|
|
8994
|
+
const isDebugMode = config.debugMode;
|
|
8995
|
+
if (config.rbkUtils.httpBehaviors.useCustomErrorMessages) {
|
|
8996
|
+
const errorMessages = config.rbkUtils.httpBehaviors.extractErrorMessageCallback(error);
|
|
8997
|
+
if (isDebugMode) {
|
|
8998
|
+
console.log('>> useCustomErrorMessages is true');
|
|
8999
|
+
console.log('>> api error response', error);
|
|
9000
|
+
console.log('>> extracted error messages', errorMessages);
|
|
9001
|
+
}
|
|
9002
|
+
return errorMessages;
|
|
9003
|
+
}
|
|
8994
9004
|
const results = [];
|
|
8995
9005
|
if (isDebugMode) {
|
|
8996
9006
|
console.log('>> getErrorMessages(state)');
|
|
@@ -50796,6 +50806,91 @@ __decorate([
|
|
|
50796
50806
|
Selector([AuthenticationState])
|
|
50797
50807
|
], TenantAuthenticationSelectors, "hasClaimAccess", null);
|
|
50798
50808
|
|
|
50809
|
+
function isStringArrayLike(value) {
|
|
50810
|
+
if (!Array.isArray(value)) {
|
|
50811
|
+
return false;
|
|
50812
|
+
}
|
|
50813
|
+
return value.every((entry) => typeof entry === 'string');
|
|
50814
|
+
}
|
|
50815
|
+
function isRfcProblemDetailsBaseLike(errorValue) {
|
|
50816
|
+
if (typeof errorValue !== 'object' || errorValue === null) {
|
|
50817
|
+
return false;
|
|
50818
|
+
}
|
|
50819
|
+
return true;
|
|
50820
|
+
}
|
|
50821
|
+
function isSafeExceptionResponseLike(errorValue, rfcTypeValue) {
|
|
50822
|
+
if (!isRfcProblemDetailsBaseLike(errorValue)) {
|
|
50823
|
+
return false;
|
|
50824
|
+
}
|
|
50825
|
+
const typedErrorValue = errorValue;
|
|
50826
|
+
const isCorrectType = typedErrorValue.type === rfcTypeValue;
|
|
50827
|
+
const isDetailString = typeof typedErrorValue.detail === 'string';
|
|
50828
|
+
const isErrorsAbsent = typeof typedErrorValue.errors === 'undefined';
|
|
50829
|
+
if (!isCorrectType) {
|
|
50830
|
+
return false;
|
|
50831
|
+
}
|
|
50832
|
+
if (!isDetailString) {
|
|
50833
|
+
return false;
|
|
50834
|
+
}
|
|
50835
|
+
if (!isErrorsAbsent) {
|
|
50836
|
+
return false;
|
|
50837
|
+
}
|
|
50838
|
+
return true;
|
|
50839
|
+
}
|
|
50840
|
+
function isValidationExceptionResponseLike(errorValue, rfcTypeValue) {
|
|
50841
|
+
if (!isRfcProblemDetailsBaseLike(errorValue)) {
|
|
50842
|
+
return false;
|
|
50843
|
+
}
|
|
50844
|
+
const typedErrorValue = errorValue;
|
|
50845
|
+
const isCorrectType = typedErrorValue.type === rfcTypeValue;
|
|
50846
|
+
const isDetailString = typeof typedErrorValue.detail === 'string';
|
|
50847
|
+
const errorsValue = typedErrorValue.errors;
|
|
50848
|
+
if (!isCorrectType) {
|
|
50849
|
+
return false;
|
|
50850
|
+
}
|
|
50851
|
+
if (!isDetailString) {
|
|
50852
|
+
return false;
|
|
50853
|
+
}
|
|
50854
|
+
if (typeof errorsValue !== 'object' || errorsValue === null || Array.isArray(errorsValue)) {
|
|
50855
|
+
return false;
|
|
50856
|
+
}
|
|
50857
|
+
const errorsRecord = errorsValue;
|
|
50858
|
+
const errorArrays = Object.values(errorsRecord);
|
|
50859
|
+
for (const errorArray of errorArrays) {
|
|
50860
|
+
if (!isStringArrayLike(errorArray)) {
|
|
50861
|
+
return false;
|
|
50862
|
+
}
|
|
50863
|
+
}
|
|
50864
|
+
return true;
|
|
50865
|
+
}
|
|
50866
|
+
function extractRfc9110ProblemDetails(error) {
|
|
50867
|
+
const errorMessages = [];
|
|
50868
|
+
const errorPayload = error instanceof HttpErrorResponse ? error.error : error;
|
|
50869
|
+
const rfcTypeValue = 'https://tools.ietf.org/html/rfc9110#section-15.5.1';
|
|
50870
|
+
if (isSafeExceptionResponseLike(errorPayload, rfcTypeValue)) {
|
|
50871
|
+
errorMessages.push(errorPayload.detail);
|
|
50872
|
+
return errorMessages;
|
|
50873
|
+
}
|
|
50874
|
+
if (isValidationExceptionResponseLike(errorPayload, rfcTypeValue)) {
|
|
50875
|
+
const validationDetail = errorPayload.detail;
|
|
50876
|
+
const errorItems = [];
|
|
50877
|
+
for (const errorValues of Object.values(errorPayload.errors)) {
|
|
50878
|
+
errorItems.push(...errorValues);
|
|
50879
|
+
}
|
|
50880
|
+
if (errorItems.length === 0) {
|
|
50881
|
+
errorMessages.push(validationDetail);
|
|
50882
|
+
return errorMessages;
|
|
50883
|
+
}
|
|
50884
|
+
errorMessages.push(validationDetail);
|
|
50885
|
+
errorMessages.push(...errorItems);
|
|
50886
|
+
return errorMessages;
|
|
50887
|
+
}
|
|
50888
|
+
if (typeof errorPayload === 'string') {
|
|
50889
|
+
errorMessages.push(errorPayload);
|
|
50890
|
+
}
|
|
50891
|
+
return errorMessages;
|
|
50892
|
+
}
|
|
50893
|
+
|
|
50799
50894
|
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-return, @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type, @typescript-eslint/typedef, no-underscore-dangle, no-console, eqeqeq, @typescript-eslint/no-unused-vars, @typescript-eslint/no-useless-constructor, @typescript-eslint/explicit-member-accessibility, max-len, no-prototype-builtins, @typescript-eslint/no-shadow, @typescript-eslint/no-empty-object-type */
|
|
50800
50895
|
class SmzUiHttpBehaviorsBuilder extends SmzBuilderUtilities {
|
|
50801
50896
|
_builder;
|
|
@@ -50804,10 +50899,24 @@ class SmzUiHttpBehaviorsBuilder extends SmzBuilderUtilities {
|
|
|
50804
50899
|
super();
|
|
50805
50900
|
this._builder = _builder;
|
|
50806
50901
|
}
|
|
50807
|
-
|
|
50902
|
+
useErrorHandlingAsToast() {
|
|
50808
50903
|
this._builder._state.rbkUtils.httpBehaviors.defaultParameters.errorHandlingType = 'toast';
|
|
50809
50904
|
return this.that;
|
|
50810
50905
|
}
|
|
50906
|
+
useErrorHandlingAsDialog() {
|
|
50907
|
+
this._builder._state.rbkUtils.httpBehaviors.defaultParameters.errorHandlingType = 'dialog';
|
|
50908
|
+
return this.that;
|
|
50909
|
+
}
|
|
50910
|
+
useRfc9110ProblemDetails() {
|
|
50911
|
+
this._builder._state.rbkUtils.httpBehaviors.extractErrorMessageCallback = extractRfc9110ProblemDetails;
|
|
50912
|
+
this._builder._state.rbkUtils.httpBehaviors.useCustomErrorMessages = true;
|
|
50913
|
+
return this.that;
|
|
50914
|
+
}
|
|
50915
|
+
useCustomProblemDetails(extractor) {
|
|
50916
|
+
this._builder._state.rbkUtils.httpBehaviors.extractErrorMessageCallback = extractor;
|
|
50917
|
+
this._builder._state.rbkUtils.httpBehaviors.useCustomErrorMessages = true;
|
|
50918
|
+
return this.that;
|
|
50919
|
+
}
|
|
50811
50920
|
get builder() {
|
|
50812
50921
|
return this._builder;
|
|
50813
50922
|
}
|
|
@@ -51099,6 +51208,8 @@ class SmzUiBuilder extends SmzBuilderUtilities {
|
|
|
51099
51208
|
useWindowsAuthentication: false,
|
|
51100
51209
|
mockedUserId: null
|
|
51101
51210
|
},
|
|
51211
|
+
useCustomErrorMessages: false,
|
|
51212
|
+
extractErrorMessageCallback: (error) => [],
|
|
51102
51213
|
},
|
|
51103
51214
|
toastConfig: {
|
|
51104
51215
|
severity: 'success',
|