mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-21 04:39:06 +00:00
Added sentry logging
This commit is contained in:
17
www/app/(errors)/handleError.ts
Normal file
17
www/app/(errors)/handleError.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import * as Sentry from "@sentry/react";
|
||||||
|
|
||||||
|
const handleError = (
|
||||||
|
setError: Function,
|
||||||
|
errorString: string,
|
||||||
|
errorObj?: any,
|
||||||
|
) => {
|
||||||
|
setError(errorString);
|
||||||
|
|
||||||
|
if (errorObj) {
|
||||||
|
Sentry.captureException(errorObj);
|
||||||
|
} else {
|
||||||
|
Sentry.captureMessage(errorString);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default handleError;
|
||||||
@@ -2,6 +2,7 @@ import { useEffect, useState } from "react";
|
|||||||
import { DefaultApi, V1TranscriptsCreateRequest } from "../api/apis/DefaultApi";
|
import { DefaultApi, V1TranscriptsCreateRequest } from "../api/apis/DefaultApi";
|
||||||
import { GetTranscript } from "../api";
|
import { GetTranscript } from "../api";
|
||||||
import { useError } from "../(errors)/errorContext";
|
import { useError } from "../(errors)/errorContext";
|
||||||
|
import handleError from "../(errors)/handleError";
|
||||||
|
|
||||||
type UseTranscript = {
|
type UseTranscript = {
|
||||||
response: GetTranscript | null;
|
response: GetTranscript | null;
|
||||||
@@ -37,7 +38,7 @@ const useTranscript = (api: DefaultApi): UseTranscript => {
|
|||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
const errorString = err.response || err.message || "Unknown error";
|
const errorString = err.response || err.message || "Unknown error";
|
||||||
setError(errorString);
|
handleError(setError, errorString, err);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
console.error("Error creating transcript:", errorString);
|
console.error("Error creating transcript:", errorString);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
V1TranscriptRecordWebrtcRequest,
|
V1TranscriptRecordWebrtcRequest,
|
||||||
} from "../api/apis/DefaultApi";
|
} from "../api/apis/DefaultApi";
|
||||||
import { useError } from "../(errors)/errorContext";
|
import { useError } from "../(errors)/errorContext";
|
||||||
|
import handleError from "../(errors)/handleError";
|
||||||
|
|
||||||
const useWebRTC = (
|
const useWebRTC = (
|
||||||
stream: MediaStream | null,
|
stream: MediaStream | null,
|
||||||
@@ -24,12 +25,16 @@ const useWebRTC = (
|
|||||||
try {
|
try {
|
||||||
p = new Peer({ initiator: true, stream: stream });
|
p = new Peer({ initiator: true, stream: stream });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError(`Failed to create WebRTC Peer: ${error.message}`);
|
handleError(
|
||||||
|
setError,
|
||||||
|
`Failed to create WebRTC Peer: ${error.message}`,
|
||||||
|
error,
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
p.on("error", (err) => {
|
p.on("error", (err) => {
|
||||||
setError(`WebRTC error: ${err.message}`);
|
handleError(setError, `WebRTC error: ${err.message}`, err);
|
||||||
});
|
});
|
||||||
|
|
||||||
p.on("signal", (data: any) => {
|
p.on("signal", (data: any) => {
|
||||||
@@ -48,14 +53,18 @@ const useWebRTC = (
|
|||||||
try {
|
try {
|
||||||
p.signal(answer);
|
p.signal(answer);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError(`Failed to signal answer: ${error.message}`);
|
handleError(
|
||||||
|
setError,
|
||||||
|
`Failed to signal answer: ${error.message}`,
|
||||||
|
error,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
const errorString =
|
const errorString =
|
||||||
"WebRTC signaling error: " +
|
"WebRTC signaling error: " +
|
||||||
(err.response || err.message || "Unknown error");
|
(err.response || err.message || "Unknown error");
|
||||||
setError(errorString);
|
handleError(setError, errorString, err);
|
||||||
console.error(errorString);
|
console.error(errorString);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Topic, FinalSummary, Status } from "./webSocketTypes";
|
import { Topic, FinalSummary, Status } from "./webSocketTypes";
|
||||||
import { useError } from "../(errors)/errorContext";
|
import { useError } from "../(errors)/errorContext";
|
||||||
|
import handleError from "../(errors)/handleError";
|
||||||
|
|
||||||
type UseWebSockets = {
|
type UseWebSockets = {
|
||||||
transcriptText: string;
|
transcriptText: string;
|
||||||
@@ -106,22 +107,32 @@ export const useWebSockets = (transcriptId: string | null): UseWebSockets => {
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
console.error("Unknown event:", message.event);
|
console.error("Unknown event:", message.event);
|
||||||
setError(`Received unknown WebSocket event: ${message.event}`);
|
handleError(
|
||||||
|
useError,
|
||||||
|
`Received unknown WebSocket event: ${message.event}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError(`Failed to process WebSocket message: ${error.message}`);
|
handleError(
|
||||||
|
useError,
|
||||||
|
`Failed to process WebSocket message: ${error.message}`,
|
||||||
|
error,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onerror = (error) => {
|
ws.onerror = (error) => {
|
||||||
console.error("WebSocket error:", error);
|
console.error("WebSocket error:", error);
|
||||||
setError("A WebSocket error occurred.");
|
handleError(useError, "A WebSocket error occurred.", error);
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onclose = (event) => {
|
ws.onclose = (event) => {
|
||||||
console.debug("WebSocket connection closed");
|
console.debug("WebSocket connection closed");
|
||||||
if (event.code !== 1000) {
|
if (event.code !== 1000) {
|
||||||
setError(`WebSocket closed unexpectedly with code: ${event.code}`);
|
handleError(
|
||||||
|
useError,
|
||||||
|
`WebSocket closed unexpectedly with code: ${event.code}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user