valtech-components 2.0.839 → 2.0.840
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.
- package/esm2022/lib/components/organisms/change-password-modal/change-password-modal.component.mjs +19 -22
- package/esm2022/lib/components/organisms/mfa-modal/mfa-modal.component.mjs +5 -5
- package/esm2022/lib/services/auth/auth.service.mjs +8 -3
- package/esm2022/lib/services/errors/index.mjs +9 -0
- package/esm2022/lib/services/errors/interpret-error.mjs +130 -0
- package/esm2022/lib/services/i18n/default-content.mjs +5 -1
- package/esm2022/lib/version.mjs +2 -2
- package/esm2022/public-api.mjs +6 -1
- package/fesm2022/valtech-components.mjs +170 -25
- package/fesm2022/valtech-components.mjs.map +1 -1
- package/lib/components/organisms/change-password-modal/change-password-modal.component.d.ts +0 -1
- package/lib/services/errors/index.d.ts +9 -0
- package/lib/services/errors/interpret-error.d.ts +63 -0
- package/lib/version.d.ts +1 -1
- package/package.json +1 -1
- package/public-api.d.ts +1 -0
|
@@ -49,7 +49,6 @@ export declare class ChangePasswordModalComponent {
|
|
|
49
49
|
/** Modo actual — `loading` mientras se consulta `checkHasPassword()`. */
|
|
50
50
|
readonly mode: import("@angular/core").Signal<PasswordModalMode>;
|
|
51
51
|
private readonly _formState;
|
|
52
|
-
constructor();
|
|
53
52
|
/** Traduce una clave del namespace `_auth`. */
|
|
54
53
|
t(key: string): string;
|
|
55
54
|
readonly formProps: import("@angular/core").Signal<FormMetadata>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error interpretation helpers.
|
|
3
|
+
*
|
|
4
|
+
* `interpretError` normaliza cualquier error (HttpErrorResponse crudo,
|
|
5
|
+
* AuthError aplanado, Error de JS, o un valor arbitrario) a un
|
|
6
|
+
* `InterpretedError` con forma estable. Función pura, sin Angular DI.
|
|
7
|
+
*/
|
|
8
|
+
export { interpretError } from './interpret-error';
|
|
9
|
+
export type { InterpretedError } from './interpret-error';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error interpretation helper for the Valtech factory.
|
|
3
|
+
*
|
|
4
|
+
* Todos los frontends del factory consumen la misma API (backend Go) y la misma
|
|
5
|
+
* librería. La lógica de interpretar errores debe vivir una sola vez, acá.
|
|
6
|
+
*
|
|
7
|
+
* El backend Go (`apperrors`) SIEMPRE devuelve errores como JSON:
|
|
8
|
+
* { "code": string, "message": string, "operationId": string }
|
|
9
|
+
* donde `message` ya viene en español y es user-friendly.
|
|
10
|
+
*
|
|
11
|
+
* En Angular un error HTTP llega como `HttpErrorResponse` (body en `.error`).
|
|
12
|
+
* Un fallo de red es un `HttpErrorResponse` con `status === 0`.
|
|
13
|
+
*
|
|
14
|
+
* Además `AuthService.handleAuthError` aplana el `HttpErrorResponse` a un
|
|
15
|
+
* `AuthError { code, message }` (code/message al nivel superior). Por eso este
|
|
16
|
+
* helper acepta AMBAS formas — el crudo y el aplanado.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Resultado normalizado de cualquier error. Garantiza una forma estable y
|
|
20
|
+
* predecible para que las webapps no tengan que hacer narrowing manual.
|
|
21
|
+
*/
|
|
22
|
+
export interface InterpretedError {
|
|
23
|
+
/** Código del backend, o el sentinel `'NETWORK'` / `'UNKNOWN'`. */
|
|
24
|
+
code: string;
|
|
25
|
+
/** Mensaje del backend (español, user-friendly) o un genérico en español. */
|
|
26
|
+
message: string;
|
|
27
|
+
/** `operationId` del backend, si vino. Útil para soporte / tracing. */
|
|
28
|
+
operationId?: string;
|
|
29
|
+
/** HTTP status, si aplica (`0` para fallos de red). */
|
|
30
|
+
status?: number;
|
|
31
|
+
/** `true` si fue un fallo de red (status 0 / sin respuesta). */
|
|
32
|
+
isNetwork: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Normaliza CUALQUIER error a un `InterpretedError`.
|
|
36
|
+
*
|
|
37
|
+
* Función pura — sin dependencias de Angular DI, testeable y usable desde
|
|
38
|
+
* cualquier lado (componentes, servicios, interceptores, scripts).
|
|
39
|
+
*
|
|
40
|
+
* Nunca lanza: siempre devuelve un `InterpretedError` válido.
|
|
41
|
+
*
|
|
42
|
+
* Casos cubiertos:
|
|
43
|
+
* - `HttpErrorResponse` con `status === 0` (o sin respuesta) → fallo de red.
|
|
44
|
+
* - `HttpErrorResponse` con body `{ code, message, operationId }` del backend.
|
|
45
|
+
* - `AuthError` aplanado `{ code, message }` (code/message top-level).
|
|
46
|
+
* - `Error` plano de JS → `code: 'UNKNOWN'`, `message: err.message`.
|
|
47
|
+
* - Cualquier otra cosa (string, null, undefined, objeto raro) → genérico.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* try {
|
|
52
|
+
* await firstValueFrom(this.http.get(url));
|
|
53
|
+
* } catch (err) {
|
|
54
|
+
* const e = interpretError(err);
|
|
55
|
+
* if (e.isNetwork) {
|
|
56
|
+
* this.toast.show({ message: e.message, color: 'dark' });
|
|
57
|
+
* } else {
|
|
58
|
+
* this.errorCode.set(e.code);
|
|
59
|
+
* }
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function interpretError(err: unknown): InterpretedError;
|
package/lib/version.d.ts
CHANGED
package/package.json
CHANGED
package/public-api.d.ts
CHANGED
|
@@ -255,6 +255,7 @@ export * from './lib/services/navigation';
|
|
|
255
255
|
export * from './lib/services/theme.service';
|
|
256
256
|
export * from './lib/services/toast.service';
|
|
257
257
|
export * from './lib/services/types';
|
|
258
|
+
export * from './lib/services/errors';
|
|
258
259
|
export * from './lib/services/confirmation-dialog/confirmation-dialog.service';
|
|
259
260
|
export * from './lib/services/confirmation-dialog/types';
|
|
260
261
|
export * from './lib/services/qr-generator/qr-generator.service';
|