Skip to content

Commit 608710a

Browse files
committed
make requests check for success instead of specific status
1 parent 8b6507c commit 608710a

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

src/index.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ fn create_mod(download_link: &str, config: &mut Config) {
235235
fatal!("Invalid token. Please login again.");
236236
}
237237

238-
if response.status() != 204 {
238+
if !response.status().is_success() {
239239
let body: ApiResponse<String> = response
240240
.json()
241241
.nice_unwrap("Unable to parse response from Geode Index");
@@ -270,7 +270,7 @@ fn update_mod(id: &str, download_link: &str, config: &mut Config) {
270270
fatal!("Invalid token. Please login again.");
271271
}
272272

273-
if response.status() != 204 {
273+
if !response.status().is_success() {
274274
let body: ApiResponse<String> = response
275275
.json()
276276
.nice_unwrap("Unable to parse response from Geode Index");
@@ -330,7 +330,7 @@ pub fn get_mod_versions(
330330
.send()
331331
.nice_unwrap("Couldn't connect to the index");
332332

333-
if response.status() != 200 {
333+
if !response.status().is_success() {
334334
return Err("Failed to fetch mod versions".to_string());
335335
}
336336

src/index_admin.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ fn get_pending_mods(page: i32, config: &Config) -> PaginatedData<PendingMod> {
180180
.send()
181181
.nice_unwrap("Failed to connect to the Geode Index");
182182

183-
if response.status() != 200 {
183+
if !response.status().is_success() {
184184
if let Ok(body) = response.json::<ApiResponse<String>>() {
185185
warn!("{}", body.error);
186186
}
@@ -310,7 +310,7 @@ fn get_developer_profile(username: &str, config: &Config) -> Option<DeveloperPro
310310
.send()
311311
.nice_unwrap("Unable to connect to Geode Index");
312312

313-
if response.status() != 200 {
313+
if !response.status().is_success() {
314314
warn!("Unable to fetch profile: {}", response.status());
315315
return None;
316316
}
@@ -374,7 +374,7 @@ fn update_dev_status(config: &Config) {
374374
.send()
375375
.nice_unwrap("Failed to update developer");
376376

377-
if response.status() != 200 {
377+
if !response.status().is_success() {
378378
let json = response.json::<serde_json::Value>();
379379
if let Ok(j) = json {
380380
if j.is_object() && j.as_object().unwrap().contains_key("error") {
@@ -406,7 +406,7 @@ fn validate_mod(version: &PendingModVersion, id: &str, config: &Config) {
406406
.send()
407407
.nice_unwrap("Failed to connect to the Geode Index");
408408

409-
if response.status() != 204 {
409+
if !response.status().is_success() {
410410
if let Ok(body) = response.json::<ApiResponse<String>>() {
411411
warn!("{}", body.error);
412412
}
@@ -433,7 +433,7 @@ fn reject_mod(version: &PendingModVersion, id: &str, config: &Config) {
433433
.send()
434434
.nice_unwrap("Failed to connect to the Geode Index");
435435

436-
if response.status() != 204 {
436+
if !response.status().is_success() {
437437
if let Ok(body) = response.json::<ApiResponse<String>>() {
438438
warn!("{}", body.error);
439439
}
@@ -454,7 +454,7 @@ fn download_mod(version: &PendingModVersion, id: &str, config: &Config) {
454454
.send()
455455
.nice_unwrap("Failed to connect to the Geode Index");
456456

457-
if response.status() != 200 {
457+
if !response.status().is_success() {
458458
if let Ok(body) = response.json::<ApiResponse<String>>() {
459459
warn!("{}", body.error);
460460
}

src/index_auth.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub fn login(config: &mut Config, token: Option<String>, github_token: Option<St
7979
.send()
8080
.nice_unwrap("Unable to connect to Geode Index");
8181

82-
if response.status() != 200 {
82+
if !response.status().is_success() {
8383
fatal!("Unable to connect to Geode Index");
8484
}
8585

@@ -123,7 +123,7 @@ fn poll_login(
123123
.send()
124124
.nice_unwrap("Unable to connect to Geode Index");
125125

126-
if response.status() != 200 {
126+
if !response.status().is_success() {
127127
return None;
128128
}
129129

@@ -186,7 +186,7 @@ fn invalidate_index_tokens(config: &mut Config) {
186186
config.save();
187187
fatal!("Invalid token. Please login again.");
188188
}
189-
if response.status() != 204 {
189+
if !response.status().is_success() {
190190
fatal!("Unable to invalidate token");
191191
}
192192
}

src/index_dev.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,19 @@ fn get_own_mods(validated: bool, config: &mut Config) -> Vec<SimpleDevMod> {
144144
.send()
145145
.nice_unwrap("Unable to connect to Geode Index");
146146

147-
if response.status() != 200 {
148-
let body: ApiResponse<String> = response
149-
.json()
150-
.nice_unwrap("Unable to parse response from Geode Index");
151-
fatal!("Unable to fetch mods: {}", body.error);
152-
}
153-
154147
if response.status() == 401 {
155148
config.index_token = None;
156149
config.save();
157150
fatal!("Invalid token. Please login again.");
158151
}
159152

153+
if !response.status().is_success() {
154+
let body: ApiResponse<String> = response
155+
.json()
156+
.nice_unwrap("Unable to parse response from Geode Index");
157+
fatal!("Unable to fetch mods: {}", body.error);
158+
}
159+
160160
let mods = response
161161
.json::<ApiResponse<Vec<SimpleDevMod>>>()
162162
.nice_unwrap("Unable to parse response from Geode Index");
@@ -248,7 +248,7 @@ fn add_developer(mod_to_edit: &SimpleDevMod, config: &mut Config) {
248248
.send()
249249
.nice_unwrap("Unable to connect to Geode Index");
250250

251-
if response.status() != 204 {
251+
if !response.status().is_success() {
252252
let body: ApiResponse<String> = response
253253
.json()
254254
.nice_unwrap("Unable to parse response from Geode Index");
@@ -274,7 +274,7 @@ fn remove_developer(mod_to_edit: &SimpleDevMod, config: &mut Config) {
274274
.send()
275275
.nice_unwrap("Unable to connect to Geode Index");
276276

277-
if response.status() != 204 {
277+
if !response.status().is_success() {
278278
let body: ApiResponse<String> = response
279279
.json()
280280
.nice_unwrap("Unable to parse response from Geode Index");
@@ -300,7 +300,7 @@ pub fn get_user_profile(config: &mut Config) -> DeveloperProfile {
300300
.send()
301301
.nice_unwrap("Unable to connect to Geode Index");
302302

303-
if response.status() != 200 {
303+
if !response.status().is_success() {
304304
let body: ApiResponse<String> = response
305305
.json()
306306
.nice_unwrap("Unable to parse response from Geode Index");
@@ -358,7 +358,7 @@ pub fn edit_profile(config: &mut Config) {
358358
.send()
359359
.nice_unwrap("Unable to connect to Geode Index");
360360

361-
if response.status() != 204 {
361+
if !response.status().is_success() {
362362
let body: ApiResponse<String> = response
363363
.json()
364364
.nice_unwrap("Unable to parse response from Geode Index");

src/project.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ fn find_index_dependency(dep: &Dependency, config: &Config) -> Result<Found, Str
184184
.send()
185185
.map_err(|x| format!("Failed to download dependency: {}", x))?;
186186

187-
if result.status() != 200 {
187+
if !result.status().is_success() {
188188
return Err(format!(
189189
"Failed to download dependency. Bad status code: {}",
190190
result.status()

0 commit comments

Comments
 (0)