Skip to content

Commit 93262ce

Browse files
committed
feat: Rewrite err checks
1 parent 49fcfc0 commit 93262ce

File tree

4 files changed

+18
-29
lines changed

4 files changed

+18
-29
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ async fn main() {
5151
.unwrap();
5252

5353
// Fetch the full data for a specific problem
54-
let problem_info = api.set_problm("two sum").await.unwrap();
54+
let problem_info = api.set_problem("two sum").await.unwrap();
5555
// Retrieve previous submissions to this problem
5656
let my_submissions = problem_info.my_submissions().await.unwrap();
5757
// Retrieve code snippets

src/lib.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ impl UserApi {
4444

4545
let client = reqwest::Client::builder()
4646
.default_headers(headers)
47-
.build()
48-
.unwrap();
47+
.build()?;
4948

5049
Ok(Self { client })
5150
}
@@ -82,7 +81,7 @@ impl UserApi {
8281
"query": query,
8382
});
8483

85-
let query = serde_json::to_string(&json_data).unwrap();
84+
let query = serde_json::to_string(&json_data)?;
8685

8786
let client = reqwest::Client::new();
8887

@@ -91,8 +90,7 @@ impl UserApi {
9190
.body(query)
9291
.headers(headers)
9392
.send()
94-
.await
95-
.unwrap()
93+
.await?
9694
.text()
9795
.await
9896
{
@@ -137,15 +135,14 @@ impl UserApi {
137135
"query": "query questionData($titleSlug: String!) {\n question(titleSlug: $titleSlug) {\n questionId\n questionFrontendId\n boundTopicId\n title\n titleSlug\n content\n translatedTitle\n translatedContent\n isPaidOnly\n canSeeQuestion\n difficulty\n likes\n dislikes\n isLiked\n similarQuestions\n exampleTestcases\n categoryTitle\n contributors {\n username\n profileUrl\n avatarUrl\n __typename\n }\n topicTags {\n name\n slug\n translatedName\n __typename\n }\n companyTagStats\n codeSnippets {\n lang\n langSlug\n code\n __typename\n }\n stats\n hints\n solution {\n id\n canSeeDetail\n paidOnly\n hasVideoSolution\n paidOnlyVideo\n __typename\n }\n status\n sampleTestCase\n metaData\n judgerAvailable\n judgeType\n mysqlSchemas\n enableRunCode\n enableTestMode\n enableDebugger\n envInfo\n libraryUrl\n adminUrl\n challengeQuestion {\n id\n date\n incompleteChallengeCount\n streakCount\n type\n __typename\n }\n __typename\n }\n}"
138136
});
139137

140-
let query = serde_json::to_string(&json_obj).unwrap();
138+
let query = serde_json::to_string(&json_obj)?;
141139

142140
let full_data = match self
143141
.client
144142
.post("https://leetcode.com/graphql/")
145143
.body(query)
146144
.send()
147-
.await
148-
.unwrap()
145+
.await?
149146
.json::<ProblemFullData>()
150147
.await
151148
{
@@ -174,15 +171,14 @@ impl UserApi {
174171
"operationName": "problemsetQuestionList"
175172
});
176173

177-
let query = serde_json::to_string(&query).unwrap();
174+
let query = serde_json::to_string(&query)?;
178175

179176
let task_info = self
180177
.client
181178
.get("https://leetcode.com/graphql/")
182179
.body(query)
183180
.send()
184-
.await
185-
.unwrap()
181+
.await?
186182
.text()
187183
.await;
188184

@@ -217,15 +213,14 @@ impl UserApi {
217213
"operationName": "problemsetQuestionList"
218214
});
219215

220-
let query = serde_json::to_string(&query).unwrap();
216+
let query = serde_json::to_string(&query)?;
221217

222218
let task_info = self
223219
.client
224220
.get("https://leetcode.com/graphql/")
225221
.body(query)
226222
.send()
227-
.await
228-
.unwrap()
223+
.await?
229224
.text()
230225
.await;
231226

src/problem_actions.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ impl Problem {
4141
))
4242
.body(json_data)
4343
.send()
44-
.await
45-
.unwrap()
44+
.await?
4645
.json::<TestCaseResp>()
4746
.await
4847
{
@@ -58,8 +57,7 @@ impl Problem {
5857
resp.interpret_id
5958
))
6059
.send()
61-
.await
62-
.unwrap()
60+
.await?
6361
.json::<TestExecutionResult>()
6462
.await?;
6563
if status.state == "SUCCESS" {
@@ -89,8 +87,7 @@ impl Problem {
8987
))
9088
.body(json_data)
9189
.send()
92-
.await
93-
.unwrap()
90+
.await?
9491
.json::<SubmissionCaseResp>()
9592
.await
9693
{
@@ -106,8 +103,7 @@ impl Problem {
106103
resp.submission_id
107104
))
108105
.send()
109-
.await
110-
.unwrap()
106+
.await?
111107
.json::<SubmExecutionResult>()
112108
.await?;
113109
if status.state == "SUCCESS" {
@@ -176,15 +172,14 @@ impl Problem {
176172
"query": "query Submissions($offset: Int!, $limit: Int!, $lastKey: String, $questionSlug: String!) {\n submissionList(offset: $offset, limit: $limit, lastKey: $lastKey, questionSlug: $questionSlug) {\n lastKey\n hasNext\n submissions {\n id\n statusDisplay\n lang\n runtime\n timestamp\n url\n isPending\n memory\n __typename\n }\n __typename\n }\n}\n"
177173
});
178174

179-
let query = serde_json::to_string(&query).unwrap();
175+
let query = serde_json::to_string(&query)?;
180176

181177
match self
182178
.client
183179
.post("https://leetcode.com/graphql/")
184180
.body(query)
185181
.send()
186-
.await
187-
.unwrap()
182+
.await?
188183
.json::<SubmList>()
189184
.await
190185
{

src/problem_build.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,14 @@ impl TaskBuilder {
226226
"operationName": "problemsetQuestionList"
227227
});
228228

229-
let query = serde_json::to_string(&query).unwrap();
229+
let query = serde_json::to_string(&query)?;
230230

231231
let task_info = self
232232
.client
233233
.get("https://leetcode.com/graphql/")
234234
.body(query)
235235
.send()
236-
.await
237-
.unwrap()
236+
.await?
238237
.text()
239238
.await;
240239

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy