diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2023-01-29 16:37:22 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2023-01-29 16:37:22 -0500 |
commit | 55fd4839da43e7ca205eaa85480786e3dfe8af6f (patch) | |
tree | 5337c4d56179c019a6695a23a0c2ff59f83cd58e /src/SMAPI.Web/Framework/Clients/UpdateManifest/UpdateManifestClient.cs | |
parent | 83aec980b3ee739fb4bc251217556b3ae44f741b (diff) | |
download | SMAPI-55fd4839da43e7ca205eaa85480786e3dfe8af6f.tar.gz SMAPI-55fd4839da43e7ca205eaa85480786e3dfe8af6f.tar.bz2 SMAPI-55fd4839da43e7ca205eaa85480786e3dfe8af6f.zip |
minor formatting, copyediting, and error-handling
Diffstat (limited to 'src/SMAPI.Web/Framework/Clients/UpdateManifest/UpdateManifestClient.cs')
-rw-r--r-- | src/SMAPI.Web/Framework/Clients/UpdateManifest/UpdateManifestClient.cs | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/src/SMAPI.Web/Framework/Clients/UpdateManifest/UpdateManifestClient.cs b/src/SMAPI.Web/Framework/Clients/UpdateManifest/UpdateManifestClient.cs index d7cf4945..88a5c2f6 100644 --- a/src/SMAPI.Web/Framework/Clients/UpdateManifest/UpdateManifestClient.cs +++ b/src/SMAPI.Web/Framework/Clients/UpdateManifest/UpdateManifestClient.cs @@ -1,19 +1,21 @@ // Copyright 2022 Jamie Taylor -using System; +using System.Net; +using System.Threading.Tasks; using Pathoschild.Http.Client; using StardewModdingAPI.Toolkit.Framework.UpdateData; -using System.Threading.Tasks; -using System.Net; -namespace StardewModdingAPI.Web.Framework.Clients.UpdateManifest { - /// <summary>An HTTP client for fetching an update manifest from an arbitrary URL.</summary> - internal class UpdateManifestClient : IUpdateManifestClient { +namespace StardewModdingAPI.Web.Framework.Clients.UpdateManifest +{ + /// <summary>An API client for fetching update metadata from an arbitrary JSON URL.</summary> + internal class UpdateManifestClient : IUpdateManifestClient + { /********* ** Fields *********/ /// <summary>The underlying HTTP client.</summary> private readonly IClient Client; + /********* ** Accessors *********/ @@ -26,30 +28,35 @@ namespace StardewModdingAPI.Web.Framework.Clients.UpdateManifest { *********/ /// <summary>Construct an instance.</summary> /// <param name="userAgent">The user agent for the API client.</param> - public UpdateManifestClient(string userAgent) { + public UpdateManifestClient(string userAgent) + { this.Client = new FluentClient() .SetUserAgent(userAgent); this.Client.Formatters.Add(new TextAsJsonMediaTypeFormatter()); } /// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary> - public void Dispose() { + public void Dispose() + { this.Client.Dispose(); } /// <inheritdoc/> - public async Task<IModPage?> GetModData(string id) { + public async Task<IModPage?> GetModData(string id) + { UpdateManifestModel? manifest; - try { + try + { manifest = await this.Client.GetAsync(id).As<UpdateManifestModel?>(); - } catch (ApiException ex) when (ex.Status == HttpStatusCode.NotFound) { - return new GenericModPage(this.SiteKey, id).SetError(RemoteModStatus.DoesNotExist, $"No update manifest found at {id}"); } - if (manifest is null) { - return new GenericModPage(this.SiteKey, id).SetError(RemoteModStatus.DoesNotExist, $"Error parsing manifest at {id}"); + catch (ApiException ex) when (ex.Status == HttpStatusCode.NotFound) + { + return new GenericModPage(this.SiteKey, id).SetError(RemoteModStatus.DoesNotExist, $"No update manifest found at {id}"); } - return new UpdateManifestModPage(id, manifest); + return manifest is not null + ? new UpdateManifestModPage(id, manifest) + : new GenericModPage(this.SiteKey, id).SetError(RemoteModStatus.DoesNotExist, $"The update manifest at {id} has an invalid format"); } } } |