Skip to content

Commit

Permalink
added error context to version manifest fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
1zun4 committed Dec 12, 2023
1 parent 7ca5fa0 commit c33c803
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src-tauri/src/minecraft/prelauncher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::utils::{download_file, get_maven_artifact_path};
///
pub(crate) async fn launch<D: Send + Sync>(launch_manifest: LaunchManifest, launching_parameter: LaunchingParameter, additional_mods: Vec<LoaderMod>, progress: LauncherData<D>, window: Arc<Mutex<tauri::Window>>) -> Result<()> {
info!("Loading minecraft version manifest...");
let mc_version_manifest = VersionManifest::download().await?;
let mc_version_manifest = VersionManifest::fetch().await?;

let build = &launch_manifest.build;
let subsystem = &launch_manifest.subsystem;
Expand Down
13 changes: 8 additions & 5 deletions src-tauri/src/minecraft/version.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{collections::HashMap, fmt, marker::PhantomData, path::{Path, PathBuf}, str::FromStr};

use anyhow::Result;
use anyhow::{Result, Context};
use tracing::{debug, info};
use tokio::fs;
use serde::{Deserialize, Deserializer, de::{self, MapAccess, Visitor}};
Expand All @@ -21,11 +21,14 @@ pub struct VersionManifest {

impl VersionManifest {

pub async fn download() -> Result<Self> {
pub async fn fetch() -> Result<Self> {
let response = HTTP_CLIENT.get("https://launchermeta.mojang.com/mc/game/version_manifest.json")
.send().await?
.error_for_status()?;
let manifest = response.json::<VersionManifest>().await?;
.send().await
.context("Connection to https://launchermeta.mojang.com/ failed. Check your internet connection.")?
.error_for_status()
.context("https://launchermeta.mojang.com/ returned with an error code, try again later!")?;
let manifest = response.json::<VersionManifest>().await
.context("Failed to parse Version Manifest, Mojang Server responded with not valid format.")?;

Ok(manifest)
}
Expand Down

0 comments on commit c33c803

Please sign in to comment.