Skip to content

Commit c14c848

Browse files
committed
Add error info
1 parent 4d30937 commit c14c848

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/components/Detect.jsx

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const Detect = () => {
99
const [loading, setLoading] = useState(false);
1010
const [result, setResult] = useState(null);
1111
const [error, setError] = useState(null);
12+
const [errorInfo, setErrorInfo] = useState(null);
1213
const [text, setText] = useState("");
1314
const [isSpeaking, setIsSpeaking] = useState(false);
1415

@@ -53,6 +54,7 @@ const Detect = () => {
5354
const handleFormSubmit = async (event) => {
5455
event.preventDefault();
5556
setError(null);
57+
setErrorInfo(null);
5658

5759
if (!image) {
5860
setError("Please select an image.");
@@ -72,6 +74,9 @@ const Detect = () => {
7274
});
7375
setResult(response.data);
7476
setText(textSelector(response.data));
77+
if (response.data.error) {
78+
setErrorInfo(`${response.data.error}. ${response.data.next_steps}`);
79+
}
7580
} catch (error) {
7681
setError("An error occurred while processing the image.");
7782
} finally {
@@ -103,6 +108,7 @@ const Detect = () => {
103108
/>
104109
</div>
105110
{error && <div>{error}</div>}
111+
{errorInfo && <div>{errorInfo}</div>}
106112
<button type="submit" className="button">
107113
{loading ? (
108114
<img className="loading-gif" src={loadingGif} alt="Loading..." />

0 commit comments

Comments
 (0)