Skip to content

Commit fe23d88

Browse files
committed
Adjust structs to add category, handle errors
1 parent edb1a30 commit fe23d88

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

peerprep/api/gateway.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const questions: { [key: string]: Question } = {
66
"difficulty": 2,
77
"title": "Two Sum",
88
"description": "Given an array of integers, return indices of the two numbers such that they add up to a specific target.",
9+
"categories": ["Hash Table", "Array"],
910
"test_cases": {
1011
"[2, 7, 11, 15], 9" : "[0, 1]",
1112
"[3, 2, 4], 6" : "[1, 2]",
@@ -17,6 +18,7 @@ const questions: { [key: string]: Question } = {
1718
"difficulty": 1,
1819
"title": "Reverse Integer",
1920
"description": "Given a 32-bit signed integer, reverse digits of an integer.",
21+
"categories": ["Math"],
2022
"test_cases": {
2123
"123" : "321",
2224
"1" : "1",
@@ -36,13 +38,13 @@ export async function fetchQuestion(questionId: string): Promise<Question|Status
3638
const response = await fetch(`${process.env.NEXT_PUBLIC_QUESTION_SERVICE}/questions/solve/${questionId}`);
3739
if (!response.ok) {
3840
return {
39-
...(await response.json()),
40-
status: response.status
41+
error: await response.text(),
42+
status: response.status
4143
};
4244
}
4345
return await response.json() as Question;
4446
} catch (err: any) {
45-
return { error: err.message, status: 0};
47+
return { error: err.message, status: 400};
4648
}
4749
}
4850

peerprep/api/structs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface QuestionBody {
88
difficulty: Difficulty;
99
title: string;
1010
description: string;
11+
categories: string[];
1112
}
1213

1314
export interface TestCase {
@@ -28,5 +29,5 @@ export interface StatusBody {
2829
}
2930

3031
export function isError(obj: Question | StatusBody): obj is StatusBody {
31-
return (obj as StatusBody).error !== undefined;
32+
return (obj as StatusBody).status !== undefined;
3233
}

0 commit comments

Comments
 (0)