diff options
Diffstat (limited to 'src/StardewModdingAPI.Web')
4 files changed, 22 insertions, 2 deletions
diff --git a/src/StardewModdingAPI.Web/Controllers/ModsController.cs b/src/StardewModdingAPI.Web/Controllers/ModsController.cs index 26cdfa31..7dcfcf13 100644 --- a/src/StardewModdingAPI.Web/Controllers/ModsController.cs +++ b/src/StardewModdingAPI.Web/Controllers/ModsController.cs @@ -106,14 +106,14 @@ namespace StardewModdingAPI.Web.Controllers // parse mod key if (!this.TryParseModKey(modKey, out string vendorKey, out string modID)) { - result[modKey] = new ModInfoModel("The mod key isn't in a valid format. It should contain the mod repository key and mod ID like 'Nexus:541'."); + result[modKey] = new ModInfoModel("The mod key isn't in a valid format. It should contain the site key and mod ID like 'Nexus:541'."); continue; } // get matching repository if (!this.Repositories.TryGetValue(vendorKey, out IModRepository repository)) { - result[modKey] = new ModInfoModel("There's no mod repository matching this namespaced mod ID."); + result[modKey] = new ModInfoModel($"There's no mod site with key '{vendorKey}'. Expected one of [{string.Join(", ", this.Repositories.Keys)}]."); continue; } diff --git a/src/StardewModdingAPI.Web/Framework/ModRepositories/ChucklefishRepository.cs b/src/StardewModdingAPI.Web/Framework/ModRepositories/ChucklefishRepository.cs index 4822c414..ed7bd60b 100644 --- a/src/StardewModdingAPI.Web/Framework/ModRepositories/ChucklefishRepository.cs +++ b/src/StardewModdingAPI.Web/Framework/ModRepositories/ChucklefishRepository.cs @@ -43,6 +43,11 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories /// <param name="id">The mod ID in this repository.</param> public override async Task<ModInfoModel> GetModInfoAsync(string id) { + // validate ID format + if (!uint.TryParse(id, out uint _)) + return new ModInfoModel($"The value '{id}' isn't a valid Chucklefish mod ID, must be an integer ID."); + + // fetch info try { // fetch HTML diff --git a/src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs b/src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs index 7dfe9f62..174fb79a 100644 --- a/src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs +++ b/src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs @@ -1,4 +1,5 @@ using System; +using System.Net; using System.Threading.Tasks; using Newtonsoft.Json; using Pathoschild.Http.Client; @@ -46,6 +47,11 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories /// <param name="id">The mod ID in this repository.</param> public override async Task<ModInfoModel> GetModInfoAsync(string id) { + // validate ID format + if (!id.Contains("/") || id.IndexOf("/", StringComparison.InvariantCultureIgnoreCase) != id.LastIndexOf("/", StringComparison.InvariantCultureIgnoreCase)) + return new ModInfoModel($"The value '{id}' isn't a valid GitHub mod ID, must be a username and project name like 'Pathoschild/LookupAnything'."); + + // fetch info try { GitRelease release = await this.Client @@ -53,6 +59,10 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories .As<GitRelease>(); return new ModInfoModel(id, this.NormaliseVersion(release.Tag), $"https://github.com/{id}/releases"); } + catch (ApiException ex) when (ex.Status == HttpStatusCode.NotFound) + { + return new ModInfoModel("Found no mod with this ID."); + } catch (Exception ex) { return new ModInfoModel(ex.ToString()); diff --git a/src/StardewModdingAPI.Web/Framework/ModRepositories/NexusRepository.cs b/src/StardewModdingAPI.Web/Framework/ModRepositories/NexusRepository.cs index e679b977..71970bec 100644 --- a/src/StardewModdingAPI.Web/Framework/ModRepositories/NexusRepository.cs +++ b/src/StardewModdingAPI.Web/Framework/ModRepositories/NexusRepository.cs @@ -38,6 +38,11 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories /// <param name="id">The mod ID in this repository.</param> public override async Task<ModInfoModel> GetModInfoAsync(string id) { + // validate ID format + if (!uint.TryParse(id, out uint _)) + return new ModInfoModel($"The value '{id}' isn't a valid Nexus mod ID, must be an integer ID."); + + // fetch info try { NexusResponseModel response = await this.Client |