mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
Merge pull request #302 from Monadical-SAS/sara/improve-errors
Proposal : improve error messages
This commit is contained in:
@@ -3,7 +3,8 @@ import React, { createContext, useContext, useState } from "react";
|
|||||||
|
|
||||||
interface ErrorContextProps {
|
interface ErrorContextProps {
|
||||||
error: Error | null;
|
error: Error | null;
|
||||||
setError: React.Dispatch<React.SetStateAction<Error | null>>;
|
humanMessage?: string;
|
||||||
|
setError: (error: Error, humanMessage?: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ErrorContext = createContext<ErrorContextProps | undefined>(undefined);
|
const ErrorContext = createContext<ErrorContextProps | undefined>(undefined);
|
||||||
@@ -22,9 +23,16 @@ interface ErrorProviderProps {
|
|||||||
|
|
||||||
export const ErrorProvider: React.FC<ErrorProviderProps> = ({ children }) => {
|
export const ErrorProvider: React.FC<ErrorProviderProps> = ({ children }) => {
|
||||||
const [error, setError] = useState<Error | null>(null);
|
const [error, setError] = useState<Error | null>(null);
|
||||||
|
const [humanMessage, setHumanMessage] = useState<string | undefined>();
|
||||||
|
|
||||||
|
const declareError = (error, humanMessage?) => {
|
||||||
|
setError(error);
|
||||||
|
setHumanMessage(humanMessage);
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<ErrorContext.Provider value={{ error, setError }}>
|
<ErrorContext.Provider
|
||||||
|
value={{ error, setError: declareError, humanMessage }}
|
||||||
|
>
|
||||||
{children}
|
{children}
|
||||||
</ErrorContext.Provider>
|
</ErrorContext.Provider>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,29 +4,51 @@ import { useEffect, useState } from "react";
|
|||||||
import * as Sentry from "@sentry/react";
|
import * as Sentry from "@sentry/react";
|
||||||
|
|
||||||
const ErrorMessage: React.FC = () => {
|
const ErrorMessage: React.FC = () => {
|
||||||
const { error, setError } = useError();
|
const { error, setError, humanMessage } = useError();
|
||||||
const [isVisible, setIsVisible] = useState<boolean>(false);
|
const [isVisible, setIsVisible] = useState<boolean>(false);
|
||||||
|
|
||||||
|
// Setup Shortcuts
|
||||||
|
useEffect(() => {
|
||||||
|
const handleKeyPress = (event: KeyboardEvent) => {
|
||||||
|
switch (event.key) {
|
||||||
|
case "^":
|
||||||
|
throw new Error("Unhandled Exception thrown by '^' shortcut");
|
||||||
|
case "$":
|
||||||
|
setError(
|
||||||
|
new Error("Unhandled Exception thrown by '$' shortcut"),
|
||||||
|
"You did this to yourself",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener("keydown", handleKeyPress);
|
||||||
|
return () => document.removeEventListener("keydown", handleKeyPress);
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (error) {
|
if (error) {
|
||||||
setIsVisible(true);
|
if (humanMessage) {
|
||||||
Sentry.captureException(error);
|
setIsVisible(true);
|
||||||
console.error("Error", error.message, error);
|
Sentry.captureException(Error(humanMessage, { cause: error }));
|
||||||
|
} else {
|
||||||
|
Sentry.captureException(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.error("Error", error);
|
||||||
}
|
}
|
||||||
}, [error]);
|
}, [error]);
|
||||||
|
|
||||||
if (!isVisible || !error) return null;
|
if (!isVisible || !humanMessage) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setIsVisible(false);
|
setIsVisible(false);
|
||||||
setError(null);
|
|
||||||
}}
|
}}
|
||||||
className="max-w-xs z-50 fixed bottom-5 right-5 md:bottom-10 md:right-10 border-solid bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded transition-opacity duration-300 ease-out opacity-100 hover:opacity-80 focus-visible:opacity-80 cursor-pointer transform hover:scale-105 focus-visible:scale-105"
|
className="max-w-xs z-50 fixed bottom-5 right-5 md:bottom-10 md:right-10 border-solid bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded transition-opacity duration-300 ease-out opacity-100 hover:opacity-80 focus-visible:opacity-80 cursor-pointer transform hover:scale-105 focus-visible:scale-105"
|
||||||
role="alert"
|
role="alert"
|
||||||
>
|
>
|
||||||
<span className="block sm:inline">{error?.message}</span>
|
<span className="block sm:inline">{humanMessage}</span>
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export default function Pagination(props: PaginationProps) {
|
|||||||
return (
|
return (
|
||||||
<div className="flex justify-center space-x-4 my-4">
|
<div className="flex justify-center space-x-4 my-4">
|
||||||
<button
|
<button
|
||||||
className={`w-10 h-10 rounded-full p-2 border border-gray-300 rounded-full disabled:bg-white ${
|
className={`w-10 h-10 rounded-full p-2 border border-gray-300 disabled:bg-white ${
|
||||||
canGoPrevious ? "text-gray-500" : "text-gray-300"
|
canGoPrevious ? "text-gray-500" : "text-gray-300"
|
||||||
}`}
|
}`}
|
||||||
onClick={() => handlePageChange(page - 1)}
|
onClick={() => handlePageChange(page - 1)}
|
||||||
@@ -52,7 +52,7 @@ export default function Pagination(props: PaginationProps) {
|
|||||||
{pageNumbers.map((pageNumber) => (
|
{pageNumbers.map((pageNumber) => (
|
||||||
<button
|
<button
|
||||||
key={pageNumber}
|
key={pageNumber}
|
||||||
className={`w-10 h-10 rounded-full p-2 border rounded-full ${
|
className={`w-10 h-10 rounded-full p-2 border ${
|
||||||
page === pageNumber ? "border-gray-600" : "border-gray-300"
|
page === pageNumber ? "border-gray-600" : "border-gray-300"
|
||||||
} rounded`}
|
} rounded`}
|
||||||
onClick={() => handlePageChange(pageNumber)}
|
onClick={() => handlePageChange(pageNumber)}
|
||||||
@@ -62,7 +62,7 @@ export default function Pagination(props: PaginationProps) {
|
|||||||
))}
|
))}
|
||||||
|
|
||||||
<button
|
<button
|
||||||
className={`w-10 h-10 rounded-full p-2 border border-gray-300 rounded-full disabled:bg-white ${
|
className={`w-10 h-10 rounded-full p-2 border border-gray-300 disabled:bg-white ${
|
||||||
canGoNext ? "text-gray-500" : "text-gray-300"
|
canGoNext ? "text-gray-500" : "text-gray-300"
|
||||||
}`}
|
}`}
|
||||||
onClick={() => handlePageChange(page + 1)}
|
onClick={() => handlePageChange(page + 1)}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export default function TranscriptDetails(details: TranscriptDetails) {
|
|||||||
transcriptId={transcript.response.id}
|
transcriptId={transcript.response.id}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{waveform?.loading === false && (
|
{!waveform?.loading && (
|
||||||
<Recorder
|
<Recorder
|
||||||
topics={topics?.topics || []}
|
topics={topics?.topics || []}
|
||||||
useActiveTopic={useActiveTopic}
|
useActiveTopic={useActiveTopic}
|
||||||
|
|||||||
@@ -45,7 +45,10 @@ const useCreateTranscript = (): CreateTranscript => {
|
|||||||
console.debug("New transcript created:", result);
|
console.debug("New transcript created:", result);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
setError(err);
|
setError(
|
||||||
|
err,
|
||||||
|
"There was an issue creating a transcript, please try again.",
|
||||||
|
);
|
||||||
setErrorState(err);
|
setErrorState(err);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import { Topic } from "./webSocketTypes";
|
|||||||
import { AudioWaveform } from "../../api";
|
import { AudioWaveform } from "../../api";
|
||||||
import AudioInputsDropdown from "./audioInputsDropdown";
|
import AudioInputsDropdown from "./audioInputsDropdown";
|
||||||
import { Option } from "react-dropdown";
|
import { Option } from "react-dropdown";
|
||||||
import { useError } from "../../(errors)/errorContext";
|
|
||||||
import { waveSurferStyles } from "../../styles/recorder";
|
import { waveSurferStyles } from "../../styles/recorder";
|
||||||
import useMp3 from "./useMp3";
|
import useMp3 from "./useMp3";
|
||||||
|
|
||||||
@@ -51,7 +50,6 @@ export default function Recorder(props: RecorderProps) {
|
|||||||
const [activeTopic, setActiveTopic] = props.useActiveTopic;
|
const [activeTopic, setActiveTopic] = props.useActiveTopic;
|
||||||
const topicsRef = useRef(props.topics);
|
const topicsRef = useRef(props.topics);
|
||||||
const [showDevices, setShowDevices] = useState(false);
|
const [showDevices, setShowDevices] = useState(false);
|
||||||
const { setError } = useError();
|
|
||||||
|
|
||||||
// Function used to setup keyboard shortcuts for the streamdeck
|
// Function used to setup keyboard shortcuts for the streamdeck
|
||||||
const setupProjectorKeys = (): (() => void) => {
|
const setupProjectorKeys = (): (() => void) => {
|
||||||
@@ -73,9 +71,6 @@ export default function Recorder(props: RecorderProps) {
|
|||||||
if (!record.isRecording()) return;
|
if (!record.isRecording()) return;
|
||||||
handleRecClick();
|
handleRecClick();
|
||||||
break;
|
break;
|
||||||
case "%":
|
|
||||||
setError(new Error("Error triggered by '%' shortcut"));
|
|
||||||
break;
|
|
||||||
case "^":
|
case "^":
|
||||||
throw new Error("Unhandled Exception thrown by '^' shortcut");
|
throw new Error("Unhandled Exception thrown by '^' shortcut");
|
||||||
case "(":
|
case "(":
|
||||||
@@ -162,7 +157,7 @@ export default function Recorder(props: RecorderProps) {
|
|||||||
if (!wavesurfer) return;
|
if (!wavesurfer) return;
|
||||||
if (!props.mp3Blob) return;
|
if (!props.mp3Blob) return;
|
||||||
wavesurfer.loadBlob(props.mp3Blob);
|
wavesurfer.loadBlob(props.mp3Blob);
|
||||||
}, [props.mp3Blob]);
|
}, [props.mp3Blob, wavesurfer]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
topicsRef.current = props.topics;
|
topicsRef.current = props.topics;
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
import { useContext, useEffect, useState } from "react";
|
import { useContext, useEffect, useState } from "react";
|
||||||
import {
|
|
||||||
DefaultApi,
|
|
||||||
// V1TranscriptGetAudioMp3Request,
|
|
||||||
} from "../../api/apis/DefaultApi";
|
|
||||||
import {} from "../../api";
|
|
||||||
import { useError } from "../../(errors)/errorContext";
|
import { useError } from "../../(errors)/errorContext";
|
||||||
import { DomainContext } from "../domainContext";
|
import { DomainContext } from "../domainContext";
|
||||||
import getApi from "../../lib/getApi";
|
import getApi from "../../lib/getApi";
|
||||||
import { useFiefAccessTokenInfo } from "@fief/fief/build/esm/nextjs/react";
|
import { useFiefAccessTokenInfo } from "@fief/fief/build/esm/nextjs/react";
|
||||||
|
import { shouldShowError } from "../../lib/errorUtils";
|
||||||
|
|
||||||
type Mp3Response = {
|
type Mp3Response = {
|
||||||
url: string | null;
|
url: string | null;
|
||||||
@@ -52,7 +48,6 @@ const useMp3 = (protectedPath: boolean, id: string): Mp3Response => {
|
|||||||
if (accessTokenInfo) {
|
if (accessTokenInfo) {
|
||||||
headers.set("Authorization", "Bearer " + accessTokenInfo.access_token);
|
headers.set("Authorization", "Bearer " + accessTokenInfo.access_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(localUrl, {
|
fetch(localUrl, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers,
|
headers,
|
||||||
@@ -65,8 +60,13 @@ const useMp3 = (protectedPath: boolean, id: string): Mp3Response => {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
setError(err);
|
|
||||||
setErrorState(err);
|
setErrorState(err);
|
||||||
|
const shouldShowHuman = shouldShowError(error);
|
||||||
|
if (shouldShowHuman) {
|
||||||
|
setError(err, "There was an error loading the audio");
|
||||||
|
} else {
|
||||||
|
setError(err);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
import { useError } from "../../(errors)/errorContext";
|
import { useError } from "../../(errors)/errorContext";
|
||||||
import { Topic } from "./webSocketTypes";
|
import { Topic } from "./webSocketTypes";
|
||||||
import getApi from "../../lib/getApi";
|
import getApi from "../../lib/getApi";
|
||||||
|
import { shouldShowError } from "../../lib/errorUtils";
|
||||||
|
|
||||||
type TranscriptTopics = {
|
type TranscriptTopics = {
|
||||||
topics: Topic[] | null;
|
topics: Topic[] | null;
|
||||||
@@ -35,8 +36,13 @@ const useTopics = (protectedPath, id: string): TranscriptTopics => {
|
|||||||
console.debug("Transcript topics loaded:", result);
|
console.debug("Transcript topics loaded:", result);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
setError(err);
|
|
||||||
setErrorState(err);
|
setErrorState(err);
|
||||||
|
const shouldShowHuman = shouldShowError(err);
|
||||||
|
if (shouldShowHuman) {
|
||||||
|
setError(err, "There was an error loading the topics");
|
||||||
|
} else {
|
||||||
|
setError(err);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}, [id, api]);
|
}, [id, api]);
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { V1TranscriptGetRequest } from "../../api/apis/DefaultApi";
|
|||||||
import { GetTranscript } from "../../api";
|
import { GetTranscript } from "../../api";
|
||||||
import { useError } from "../../(errors)/errorContext";
|
import { useError } from "../../(errors)/errorContext";
|
||||||
import getApi from "../../lib/getApi";
|
import getApi from "../../lib/getApi";
|
||||||
|
import { shouldShowError } from "../../lib/errorUtils";
|
||||||
|
|
||||||
type Transcript = {
|
type Transcript = {
|
||||||
response: GetTranscript | null;
|
response: GetTranscript | null;
|
||||||
@@ -34,9 +35,14 @@ const useTranscript = (
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
console.debug("Transcript Loaded:", result);
|
console.debug("Transcript Loaded:", result);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((error) => {
|
||||||
setError(err);
|
const shouldShowHuman = shouldShowError(error);
|
||||||
setErrorState(err);
|
if (shouldShowHuman) {
|
||||||
|
setError(error, "There was an error loading the transcript");
|
||||||
|
} else {
|
||||||
|
setError(error);
|
||||||
|
}
|
||||||
|
setErrorState(error);
|
||||||
});
|
});
|
||||||
}, [id, !api]);
|
}, [id, !api]);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
import { AudioWaveform } from "../../api";
|
import { AudioWaveform } from "../../api";
|
||||||
import { useError } from "../../(errors)/errorContext";
|
import { useError } from "../../(errors)/errorContext";
|
||||||
import getApi from "../../lib/getApi";
|
import getApi from "../../lib/getApi";
|
||||||
|
import { shouldShowError } from "../../lib/errorUtils";
|
||||||
|
|
||||||
type AudioWaveFormResponse = {
|
type AudioWaveFormResponse = {
|
||||||
waveform: AudioWaveform | null;
|
waveform: AudioWaveform | null;
|
||||||
@@ -22,7 +23,6 @@ const useWaveform = (protectedPath, id: string): AudioWaveFormResponse => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!id || !api) return;
|
if (!id || !api) return;
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const requestParameters: V1TranscriptGetAudioWaveformRequest = {
|
const requestParameters: V1TranscriptGetAudioWaveformRequest = {
|
||||||
transcriptId: id,
|
transcriptId: id,
|
||||||
@@ -35,8 +35,13 @@ const useWaveform = (protectedPath, id: string): AudioWaveFormResponse => {
|
|||||||
console.debug("Transcript waveform loaded:", result);
|
console.debug("Transcript waveform loaded:", result);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
setError(err);
|
|
||||||
setErrorState(err);
|
setErrorState(err);
|
||||||
|
const shouldShowHuman = shouldShowError(err);
|
||||||
|
if (shouldShowHuman) {
|
||||||
|
setError(err, "There was an error loading the waveform");
|
||||||
|
} else {
|
||||||
|
setError(err);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}, [id, api]);
|
}, [id, api]);
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ const useWebRTC = (
|
|||||||
try {
|
try {
|
||||||
p = new Peer({ initiator: true, stream: stream });
|
p = new Peer({ initiator: true, stream: stream });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError(error);
|
setError(error, "Error creating WebRTC");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ const useWebRTC = (
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
setError(error);
|
setError(error, "Error loading WebRTCOffer");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export const useWebSockets = (transcriptId: string | null): UseWebSockets => {
|
|||||||
const [finalSummary, setFinalSummary] = useState<FinalSummary>({
|
const [finalSummary, setFinalSummary] = useState<FinalSummary>({
|
||||||
summary: "",
|
summary: "",
|
||||||
});
|
});
|
||||||
const [status, setStatus] = useState<Status>({ value: "disconnected" });
|
const [status, setStatus] = useState<Status>({ value: "initial" });
|
||||||
const { setError } = useError();
|
const { setError } = useError();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
@@ -350,11 +350,14 @@ export const useWebSockets = (transcriptId: string | null): UseWebSockets => {
|
|||||||
if (message.data.value === "ended") {
|
if (message.data.value === "ended") {
|
||||||
const newUrl = "/transcripts/" + transcriptId;
|
const newUrl = "/transcripts/" + transcriptId;
|
||||||
router.push(newUrl);
|
router.push(newUrl);
|
||||||
console.debug(
|
console.debug("FINAL_LONG_SUMMARY event:", message.data);
|
||||||
"FINAL_LONG_SUMMARY event:",
|
}
|
||||||
message.data,
|
if (message.data.value === "error") {
|
||||||
"newUrl",
|
const newUrl = "/transcripts/" + transcriptId;
|
||||||
newUrl,
|
router.push(newUrl);
|
||||||
|
setError(
|
||||||
|
Error("Websocket error status"),
|
||||||
|
"There was an error processing this meeting.",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
setStatus(message.data);
|
setStatus(message.data);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { isDevelopment } from "./utils";
|
|||||||
|
|
||||||
const localConfig = {
|
const localConfig = {
|
||||||
features: {
|
features: {
|
||||||
requireLogin: false,
|
requireLogin: true,
|
||||||
privacy: true,
|
privacy: true,
|
||||||
browse: true,
|
browse: true,
|
||||||
},
|
},
|
||||||
|
|||||||
8
www/app/lib/errorUtils.ts
Normal file
8
www/app/lib/errorUtils.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
function shouldShowError(error: Error | null | undefined) {
|
||||||
|
if (error?.name == "ResponseError" && error["response"].status == 404)
|
||||||
|
return false;
|
||||||
|
if (error?.name == "FetchError") return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { shouldShowError };
|
||||||
@@ -14,9 +14,7 @@ export default function getApi(protectedPath: boolean): DefaultApi | undefined {
|
|||||||
if (!api_url) throw new Error("no API URL");
|
if (!api_url) throw new Error("no API URL");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// console.log('trying auth', protectedPath, requireLogin, accessTokenInfo)
|
|
||||||
if (protectedPath && requireLogin && !accessTokenInfo) {
|
if (protectedPath && requireLogin && !accessTokenInfo) {
|
||||||
// console.log('waiting auth')
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user