Triage error and better websocket handling

This commit is contained in:
Sara
2023-11-03 17:15:03 +01:00
parent 08b6d05f39
commit 26330b9de2
11 changed files with 45 additions and 28 deletions

View File

@@ -28,9 +28,6 @@ export const ErrorProvider: React.FC<ErrorProviderProps> = ({ children }) => {
const declareError = (error, humanMessage?) => { const declareError = (error, humanMessage?) => {
setError(error); setError(error);
setHumanMessage(humanMessage); setHumanMessage(humanMessage);
console.log(error.message, { ...error });
//TODO ignore not found in request errors (in useTopics, useTranscript...)
// if (error.name == ResponseError && error.response.status == 404)
}; };
return ( return (
<ErrorContext.Provider <ErrorContext.Provider

View File

@@ -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)}

View File

@@ -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}

View File

@@ -157,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;

View File

@@ -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 { shouldShowGet } 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, "There was an error loading the audio");
setErrorState(err); setErrorState(err);
const shouldShowHuman = shouldShowGet(error);
if (shouldShowHuman) {
setError(err, "There was an error loading the audio");
} else {
setError(err);
}
}); });
}; };

View File

@@ -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 { shouldShowGet } 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, "There was an error loading the topics");
setErrorState(err); setErrorState(err);
const shouldShowHuman = shouldShowGet(err);
if (shouldShowHuman) {
setError(err, "There was an error loading the topics");
} else {
setError(err);
}
}); });
}, [id, api]); }, [id, api]);

View File

@@ -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 { shouldShowGet } from "../../lib/errorUtils";
type Transcript = { type Transcript = {
response: GetTranscript | null; response: GetTranscript | null;
@@ -34,9 +35,15 @@ const useTranscript = (
setLoading(false); setLoading(false);
console.debug("Transcript Loaded:", result); console.debug("Transcript Loaded:", result);
}) })
.catch((err) => { .catch((error) => {
setError(err, "There was an error loading the transcript"); const shouldShowHuman = shouldShowGet(error);
setErrorState(err); console.log({ ...error });
if (shouldShowHuman) {
setError(error, "There was an error loading the transcript");
} else {
setError(error);
}
setErrorState(error);
}); });
}, [id, !api]); }, [id, !api]);

View File

@@ -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 { shouldShowGet } from "../../lib/errorUtils";
type AudioWaveFormResponse = { type AudioWaveFormResponse = {
waveform: AudioWaveform | null; waveform: AudioWaveform | null;
@@ -22,7 +23,7 @@ const useWaveform = (protectedPath, id: string): AudioWaveFormResponse => {
useEffect(() => { useEffect(() => {
if (!id || !api) return; if (!id || !api) return;
console.log("hee");
setLoading(true); setLoading(true);
const requestParameters: V1TranscriptGetAudioWaveformRequest = { const requestParameters: V1TranscriptGetAudioWaveformRequest = {
transcriptId: id, transcriptId: id,
@@ -35,8 +36,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, "There was an error loading the waveform");
setErrorState(err); setErrorState(err);
const shouldShowHuman = shouldShowGet(err);
if (shouldShowHuman) {
setError(err, "There was an error loading the waveform");
} else {
setError(err);
}
}); });
}, [id, api]); }, [id, api]);

View File

@@ -350,20 +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,
"newUrl",
newUrl,
);
} }
if (message.data.value === "error") { if (message.data.value === "error") {
const newUrl = "/transcripts/" + transcriptId; const newUrl = "/transcripts/" + transcriptId;
router.push(newUrl); router.push(newUrl);
// TODO Test
setError( setError(
Error("Websocket error status"), Error("Websocket error status"),
"There was an issue processing your transcript", "There was an error processing this meeting.",
); );
} }
setStatus(message.data); setStatus(message.data);

View File

@@ -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,
}, },

View File

@@ -0,0 +1,7 @@
function shouldShowGet(error: Error | null | undefined) {
if (error?.name == "ResponseError" && error["response"].status == 404)
return false;
return true;
}
export { shouldShowGet };