More robust error handling & Display errors to user

This commit is contained in:
Koper
2023-08-31 19:11:22 +07:00
parent df078f7bd6
commit 11bd568a6b
7 changed files with 139 additions and 41 deletions

View File

@@ -1,19 +1,18 @@
import { useEffect, useState } from "react";
import { DefaultApi, V1TranscriptsCreateRequest } from "../api/apis/DefaultApi";
import { GetTranscript } from "../api";
import getApi from "../lib/getApi";
import { useError } from "../(errors)/errorContext";
type UseTranscript = {
response: GetTranscript | null;
loading: boolean;
error: string | null;
createTranscript: () => void;
};
const useTranscript = (api: DefaultApi): UseTranscript => {
const [response, setResponse] = useState<GetTranscript | null>(null);
const [loading, setLoading] = useState<boolean>(false);
const [error, setError] = useState<string | null>(null);
const { setError } = useError();
const createTranscript = () => {
setLoading(true);
@@ -48,7 +47,7 @@ const useTranscript = (api: DefaultApi): UseTranscript => {
createTranscript();
}, []);
return { response, loading, error, createTranscript };
return { response, loading, createTranscript };
};
export default useTranscript;