Skip to content

Commit 7e49c0c

Browse files
committed
feat: add error msg for duplicate qn names
1 parent 64a13d3 commit 7e49c0c

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

frontend/src/app/api/index.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,15 @@ export const createQuestionUrl = async (newQuestion: QuestionType) => {
121121
"Content-Type": "application/json",
122122
},
123123
body: JSON.stringify(newQuestion),
124-
}).then((res) => res.json());
124+
})
125+
.then((res) => res.json())
126+
.then((res) => {
127+
console.log({ res });
128+
if (res.statusMessage?.type?.toLowerCase() === "error") {
129+
throw Error();
130+
}
131+
return res;
132+
});
125133
};
126134

127135
export const updateQuestionUrl = async (updatedQuestion: QuestionType) => {
@@ -131,7 +139,15 @@ export const updateQuestionUrl = async (updatedQuestion: QuestionType) => {
131139
"Content-Type": "application/json",
132140
},
133141
body: JSON.stringify(updatedQuestion),
134-
}).then((res) => res.json());
142+
})
143+
.then((res) => res.json())
144+
.then((res) => {
145+
console.log({ res });
146+
if (res.statusMessage?.type?.toLowerCase() === "error") {
147+
throw Error();
148+
}
149+
return res;
150+
});
135151
};
136152

137153
export const deleteQuestionUrl = async (questionId: string) => {

frontend/src/app/components/modal/AddQuestionModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const AddQuestionModal = ({
7070
onError: (e) => {
7171
api.open({
7272
type: "error",
73-
content: "Failed to add question!",
73+
content: "Failed to add question due to same name!",
7474
});
7575
},
7676
},
@@ -93,7 +93,7 @@ const AddQuestionModal = ({
9393
};
9494

9595
console.log("Form Submission Data:", submissionData);
96-
createQuestionMutation.mutate(submissionData);
96+
createQuestionMutation && createQuestionMutation.mutate(submissionData);
9797
e.currentTarget.reset();
9898
setDefaultValues();
9999
closeModal("my_modal_1");

frontend/src/app/components/modal/EditQuestionModal.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ const EditQuestionModal = ({
6969
successCallback();
7070
},
7171
onError: (e) => {
72-
console.log({ e });
7372
api.open({
7473
type: "error",
7574
content: "Failed to add question due to having same question name!",

0 commit comments

Comments
 (0)