fetcher throws error when quizId is ""

This commit is contained in:
nflnkr 2024-05-01 11:12:06 +03:00
parent a019843653
commit e72f5c8fca

@ -42,7 +42,7 @@ type PublicationMakeRequestParams = {
url: string; url: string;
body: FormData; body: FormData;
method: "POST"; method: "POST";
} };
export const publicationMakeRequest = ({ url, body }: PublicationMakeRequestParams) => { export const publicationMakeRequest = ({ url, body }: PublicationMakeRequestParams) => {
return axios(url, { return axios(url, {
@ -50,10 +50,10 @@ export const publicationMakeRequest = ({ url, body }: PublicationMakeRequestPara
headers: { headers: {
"X-Sessionkey": SESSIONS, "X-Sessionkey": SESSIONS,
"Content-Type": "multipart/form-data", "Content-Type": "multipart/form-data",
"DeviceType" : DeviceType, "DeviceType": DeviceType,
"Device" : Device, "Device": Device,
"OS": OSDevice, "OS": OSDevice,
"Browser" : browserUser "Browser": browserUser
}, },
method: "POST", method: "POST",
}); });
@ -72,10 +72,10 @@ export async function getData(quizId: string): Promise<{
headers: { headers: {
"X-Sessionkey": SESSIONS, "X-Sessionkey": SESSIONS,
"Content-Type": "application/json", "Content-Type": "application/json",
"DeviceType" : DeviceType, "DeviceType": DeviceType,
"Device" : Device, "Device": Device,
"OS": OSDevice, "OS": OSDevice,
"Browser" : userAgent "Browser": userAgent
}, },
data: { data: {
quiz_id: quizId, quiz_id: quizId,
@ -105,6 +105,8 @@ export async function getData(quizId: string): Promise<{
} }
export async function getQuizData(quizId: string) { export async function getQuizData(quizId: string) {
if (!quizId) throw new Error("No quiz id");
const response = await getData(quizId); const response = await getData(quizId);
const quizDataResponse = response.data; const quizDataResponse = response.data;
@ -127,7 +129,7 @@ type SendAnswerProps = {
body: string | string[]; body: string | string[];
qid: string; qid: string;
preview: boolean; preview: boolean;
} };
export function sendAnswer({ questionId, body, qid, preview }: SendAnswerProps) { export function sendAnswer({ questionId, body, qid, preview }: SendAnswerProps) {
if (preview) return; if (preview) return;
@ -159,7 +161,7 @@ type SendFileParams = {
preview: boolean; preview: boolean;
}; };
qid: string; qid: string;
} };
type Answer = { type Answer = {
question_id: string; question_id: string;
@ -201,7 +203,7 @@ export type SendFCParams = {
}; };
qid: string; qid: string;
preview: boolean; preview: boolean;
} };
export function sendFC({ questionId, body, qid, preview }: SendFCParams) { export function sendFC({ questionId, body, qid, preview }: SendFCParams) {
if (preview) return; if (preview) return;