Break error words without breakLongWord (#16)
* List number of scenarios * Remove breakLongWords
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import { type ModelOutput } from "@prisma/client";
|
import { type ModelOutput } from "@prisma/client";
|
||||||
import { HStack, VStack, Text, Button, Icon } from "@chakra-ui/react";
|
import { HStack, VStack, Text, Button, Icon } from "@chakra-ui/react";
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { BsArrowClockwise } from "react-icons/bs";
|
import { BsArrowClockwise } from "react-icons/bs";
|
||||||
import { rateLimitErrorMessage } from "~/sharedStrings";
|
import { rateLimitErrorMessage } from "~/sharedStrings";
|
||||||
import pluralize from 'pluralize'
|
import pluralize from "pluralize";
|
||||||
|
|
||||||
const MAX_AUTO_RETRIES = 3;
|
const MAX_AUTO_RETRIES = 3;
|
||||||
|
|
||||||
@@ -20,8 +20,6 @@ export const ErrorHandler = ({
|
|||||||
const shouldAutoRetry =
|
const shouldAutoRetry =
|
||||||
output.errorMessage === rateLimitErrorMessage && numPreviousTries < MAX_AUTO_RETRIES;
|
output.errorMessage === rateLimitErrorMessage && numPreviousTries < MAX_AUTO_RETRIES;
|
||||||
|
|
||||||
const errorMessage = useMemo(() => breakLongWords(output.errorMessage), [output.errorMessage]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!shouldAutoRetry) return;
|
if (!shouldAutoRetry) return;
|
||||||
|
|
||||||
@@ -71,27 +69,18 @@ export const ErrorHandler = ({
|
|||||||
<Icon as={BsArrowClockwise} boxSize={6} />
|
<Icon as={BsArrowClockwise} boxSize={6} />
|
||||||
</Button>
|
</Button>
|
||||||
</HStack>
|
</HStack>
|
||||||
<Text color="red.600">{errorMessage}</Text>
|
<Text color="red.600" wordBreak="break-word">
|
||||||
|
{output.errorMessage}
|
||||||
|
</Text>
|
||||||
{msToWait > 0 && (
|
{msToWait > 0 && (
|
||||||
<Text color="red.600" fontSize="sm">
|
<Text color="red.600" fontSize="sm">
|
||||||
Retrying in {pluralize('second', Math.ceil(msToWait / 1000), true)}...
|
Retrying in {pluralize("second", Math.ceil(msToWait / 1000), true)}...
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
</VStack>
|
</VStack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
function breakLongWords(str: string | null): string {
|
|
||||||
if (!str) return "";
|
|
||||||
const words = str.split(" ");
|
|
||||||
|
|
||||||
const newWords = words.map((word) => {
|
|
||||||
return word.length > 20 ? word.slice(0, 20) + "\u200B" + word.slice(20) : word;
|
|
||||||
});
|
|
||||||
|
|
||||||
return newWords.join(" ");
|
|
||||||
}
|
|
||||||
|
|
||||||
const MIN_DELAY = 500; // milliseconds
|
const MIN_DELAY = 500; // milliseconds
|
||||||
const MAX_DELAY = 5000; // milliseconds
|
const MAX_DELAY = 5000; // milliseconds
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user