@olimpo/error-client
v1.0.14
Published
Cliente de captura de errores e interacciones para aplicaciones Olimpo.
Readme
@olimpo/error-client
Cliente de captura de errores e interacciones para aplicaciones Olimpo.
Instalación
npm install @olimpo/error-client
# o
pnpm add @olimpo/error-clientUso
Inicialización
import { OlimpoErrorClient } from "@olimpo/error-client";
import { SessionManager } from "@calimaco/base_v2";
import cfg from "./utils/Config";
// Inicializar con SessionManager (opcional)
const session = new SessionManager(cfg);
OlimpoErrorClient.init({
sessionProvider: session,
apiUrl: "https://api.example.com/api", // opcional
});Captura de Errores
import { OlimpoErrorClient } from "@olimpo/error-client";
// Captura manual
OlimpoErrorClient.captureException({
event_type: "error",
message: "Error description",
level: "error",
fingerprint: "unique-error-id",
stack_trace: [
{
file: "component.tsx",
line: 42,
function: "handleClick",
},
],
});
// Captura segura (no lanza excepciones)
OlimpoErrorClient.captureExceptionSafe({
event_type: "error",
message: "Error description",
level: "warning",
});Hook de Captura de Errores
import { useCaptureError } from "@olimpo/error-client";
function MyComponent() {
const { captureError } = useCaptureError();
const handleAction = () => {
try {
// código que puede fallar
} catch (error) {
captureError(error, {
event_type: "user_action_error",
level: "error",
tags: { action: "submit_form" },
});
}
};
}Captura de Interacciones
import { OlimpoErrorClient } from "@olimpo/error-client";
// Captura manual
OlimpoErrorClient.captureInteraction({
event_type: "click",
component_name: "LoginButton",
action: "click",
metadata: {
page: "/login",
element: "submit-btn",
},
});
// Captura segura
OlimpoErrorClient.captureInteractionSafe({
event_type: "page_view",
component_name: "HomePage",
});Hook de Captura de Interacciones
import { useCaptureInteraction } from "@olimpo/error-client";
function MyComponent() {
const captureInteraction = useCaptureInteraction();
const handleClick = () => {
captureInteraction({
event_type: "click",
component_name: "ProductCard",
action: "add_to_cart",
metadata: { productId: "123" },
});
};
}ErrorBoundary
import { ErrorBoundary } from "@olimpo/error-client";
function App() {
return (
<ErrorBoundary>
<YourApp />
</ErrorBoundary>
);
}API
OlimpoErrorClient
init(options)
Inicializa el cliente.
Opciones:
sessionProvider?: SessionProvider- Proveedor de sesión de usuarioapiUrl?: string- URL base de la API (por defecto usaREACT_APP_OLIMPO_API)
isInitialized(): boolean
Verifica si el cliente está inicializado.
captureException(payload): Promise<ErrorEventResponse>
Captura un error de forma asíncrona.
captureExceptionSafe(payload): void
Captura un error de forma segura (no lanza excepciones).
captureInteraction(payload): Promise<void>
Captura una interacción de usuario.
captureInteractionSafe(payload): void
Captura una interacción de forma segura.
isPWA(): boolean
Detecta si la aplicación se ejecuta como PWA.
getPlatformInfo()
Obtiene información de la plataforma (OS, navegador, tipo de dispositivo).
Variables de Entorno
REACT_APP_OLIMPO_API=https://api.example.com/api
REACT_APP_OLIMPO_CAPTURE_ERROR_PROJECT_SLUG=my-project
REACT_APP_OLIMPO_CAPTURE_ERROR_ENVIRONMENT_NAME=production
REACT_APP_OLIMPO_CAPTURE_ERROR_TOKEN=your-auth-token
REACT_APP_COUNTRY=PETipos
interface SessionProvider {
getUser: () => UserContext | undefined;
}
interface UserContext {
user?: string;
alias?: string;
email?: string;
mobile?: string;
national_id?: string;
}Licencia
Privado - Olimpo
