summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Framework/Clients/Pastebin
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI.Web/Framework/Clients/Pastebin')
-rw-r--r--src/SMAPI.Web/Framework/Clients/Pastebin/IPastebinClient.cs2
-rw-r--r--src/SMAPI.Web/Framework/Clients/Pastebin/PasteInfo.cs28
-rw-r--r--src/SMAPI.Web/Framework/Clients/Pastebin/PastebinClient.cs14
3 files changed, 29 insertions, 15 deletions
diff --git a/src/SMAPI.Web/Framework/Clients/Pastebin/IPastebinClient.cs b/src/SMAPI.Web/Framework/Clients/Pastebin/IPastebinClient.cs
index 03c78e01..431fed7b 100644
--- a/src/SMAPI.Web/Framework/Clients/Pastebin/IPastebinClient.cs
+++ b/src/SMAPI.Web/Framework/Clients/Pastebin/IPastebinClient.cs
@@ -1,5 +1,3 @@
-#nullable disable
-
using System;
using System.Threading.Tasks;
diff --git a/src/SMAPI.Web/Framework/Clients/Pastebin/PasteInfo.cs b/src/SMAPI.Web/Framework/Clients/Pastebin/PasteInfo.cs
index 2d48a7ae..7f40e713 100644
--- a/src/SMAPI.Web/Framework/Clients/Pastebin/PasteInfo.cs
+++ b/src/SMAPI.Web/Framework/Clients/Pastebin/PasteInfo.cs
@@ -1,17 +1,35 @@
-#nullable disable
+using System.Diagnostics.CodeAnalysis;
namespace StardewModdingAPI.Web.Framework.Clients.Pastebin
{
/// <summary>The response for a get-paste request.</summary>
internal class PasteInfo
{
+ /*********
+ ** Accessors
+ *********/
/// <summary>Whether the log was successfully fetched.</summary>
- public bool Success { get; set; }
+ [MemberNotNullWhen(true, nameof(PasteInfo.Content))]
+ [MemberNotNullWhen(false, nameof(PasteInfo.Error))]
+ public bool Success => this.Error == null || this.Content != null;
/// <summary>The fetched paste content (if <see cref="Success"/> is <c>true</c>).</summary>
- public string Content { get; set; }
+ public string? Content { get; internal set; }
- /// <summary>The error message if saving failed.</summary>
- public string Error { get; set; }
+ /// <summary>The error message (if <see cref="Success"/> is <c>false</c>).</summary>
+ public string? Error { get; }
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="content">The fetched paste content.</param>
+ /// <param name="error">The error message, if it failed.</param>
+ public PasteInfo(string? content, string? error)
+ {
+ this.Content = content;
+ this.Error = error;
+ }
}
}
diff --git a/src/SMAPI.Web/Framework/Clients/Pastebin/PastebinClient.cs b/src/SMAPI.Web/Framework/Clients/Pastebin/PastebinClient.cs
index d0cdf374..0e00f071 100644
--- a/src/SMAPI.Web/Framework/Clients/Pastebin/PastebinClient.cs
+++ b/src/SMAPI.Web/Framework/Clients/Pastebin/PastebinClient.cs
@@ -1,5 +1,3 @@
-#nullable disable
-
using System;
using System.Net;
using System.Threading.Tasks;
@@ -35,24 +33,24 @@ namespace StardewModdingAPI.Web.Framework.Clients.Pastebin
try
{
// get from API
- string content = await this.Client
+ string? content = await this.Client
.GetAsync($"raw/{id}")
.AsString();
// handle Pastebin errors
if (string.IsNullOrWhiteSpace(content))
- return new PasteInfo { Error = "Received an empty response from Pastebin." };
+ return new PasteInfo(null, "Received an empty response from Pastebin.");
if (content.StartsWith("<!DOCTYPE"))
- return new PasteInfo { Error = $"Received a captcha challenge from Pastebin. Please visit https://pastebin.com/{id} in a new window to solve it." };
- return new PasteInfo { Success = true, Content = content };
+ return new PasteInfo(null, $"Received a captcha challenge from Pastebin. Please visit https://pastebin.com/{id} in a new window to solve it.");
+ return new PasteInfo(content, null);
}
catch (ApiException ex) when (ex.Status == HttpStatusCode.NotFound)
{
- return new PasteInfo { Error = "There's no log with that ID." };
+ return new PasteInfo(null, "There's no log with that ID.");
}
catch (Exception ex)
{
- return new PasteInfo { Error = $"Pastebin error: {ex}" };
+ return new PasteInfo(null, $"Pastebin error: {ex}");
}
}