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?) => {
setError(error);
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 (
<ErrorContext.Provider

View File

@@ -40,7 +40,7 @@ export default function Pagination(props: PaginationProps) {
return (
<div className="flex justify-center space-x-4 my-4">
<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"
}`}
onClick={() => handlePageChange(page - 1)}

View File

@@ -61,7 +61,7 @@ export default function TranscriptDetails(details: TranscriptDetails) {
transcriptId={transcript.response.id}
/>
)}
{waveform?.loading === false && (
{!waveform?.loading && (
<Recorder
topics={topics?.topics || []}
useActiveTopic={useActiveTopic}

View File

@@ -157,7 +157,7 @@ export default function Recorder(props: RecorderProps) {
if (!wavesurfer) return;
if (!props.mp3Blob) return;
wavesurfer.loadBlob(props.mp3Blob);
}, [props.mp3Blob]);
}, [props.mp3Blob, wavesurfer]);
useEffect(() => {
topicsRef.current = props.topics;

View File

@@ -1,13 +1,9 @@
import { useContext, useEffect, useState } from "react";
import {
DefaultApi,
// V1TranscriptGetAudioMp3Request,
} from "../../api/apis/DefaultApi";
import {} from "../../api";
import { useError } from "../../(errors)/errorContext";
import { DomainContext } from "../domainContext";
import getApi from "../../lib/getApi";
import { useFiefAccessTokenInfo } from "@fief/fief/build/esm/nextjs/react";
import { shouldShowGet } from "../../lib/errorUtils";
type Mp3Response = {
url: string | null;
@@ -52,7 +48,6 @@ const useMp3 = (protectedPath: boolean, id: string): Mp3Response => {
if (accessTokenInfo) {
headers.set("Authorization", "Bearer " + accessTokenInfo.access_token);
}
fetch(localUrl, {
method: "GET",
headers,
@@ -65,8 +60,13 @@ const useMp3 = (protectedPath: boolean, id: string): Mp3Response => {
});
})
.catch((err) => {
setError(err, "There was an error loading the audio");
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 { Topic } from "./webSocketTypes";
import getApi from "../../lib/getApi";
import { shouldShowGet } from "../../lib/errorUtils";
type TranscriptTopics = {
topics: Topic[] | null;
@@ -35,8 +36,13 @@ const useTopics = (protectedPath, id: string): TranscriptTopics => {
console.debug("Transcript topics loaded:", result);
})
.catch((err) => {
setError(err, "There was an error loading the topics");
setErrorState(err);
const shouldShowHuman = shouldShowGet(err);
if (shouldShowHuman) {
setError(err, "There was an error loading the topics");
} else {
setError(err);
}
});
}, [id, api]);

View File

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

View File

@@ -6,6 +6,7 @@ import {
import { AudioWaveform } from "../../api";
import { useError } from "../../(errors)/errorContext";
import getApi from "../../lib/getApi";
import { shouldShowGet } from "../../lib/errorUtils";
type AudioWaveFormResponse = {
waveform: AudioWaveform | null;
@@ -22,7 +23,7 @@ const useWaveform = (protectedPath, id: string): AudioWaveFormResponse => {
useEffect(() => {
if (!id || !api) return;
console.log("hee");
setLoading(true);
const requestParameters: V1TranscriptGetAudioWaveformRequest = {
transcriptId: id,
@@ -35,8 +36,13 @@ const useWaveform = (protectedPath, id: string): AudioWaveFormResponse => {
console.debug("Transcript waveform loaded:", result);
})
.catch((err) => {
setError(err, "There was an error loading the waveform");
setErrorState(err);
const shouldShowHuman = shouldShowGet(err);
if (shouldShowHuman) {
setError(err, "There was an error loading the waveform");
} else {
setError(err);
}
});
}, [id, api]);

View File

@@ -350,20 +350,14 @@ export const useWebSockets = (transcriptId: string | null): UseWebSockets => {
if (message.data.value === "ended") {
const newUrl = "/transcripts/" + transcriptId;
router.push(newUrl);
console.debug(
"FINAL_LONG_SUMMARY event:",
message.data,
"newUrl",
newUrl,
);
console.debug("FINAL_LONG_SUMMARY event:", message.data);
}
if (message.data.value === "error") {
const newUrl = "/transcripts/" + transcriptId;
router.push(newUrl);
// TODO Test
setError(
Error("Websocket error status"),
"There was an issue processing your transcript",
"There was an error processing this meeting.",
);
}
setStatus(message.data);

View File

@@ -3,7 +3,7 @@ import { isDevelopment } from "./utils";
const localConfig = {
features: {
requireLogin: false,
requireLogin: true,
privacy: 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 };