From d8503001eb9737311e8d7ba8ac68138b46279cf1 Mon Sep 17 00:00:00 2001 From: Ske Date: Mon, 12 Aug 2019 17:47:35 +0200 Subject: [PATCH] Show an error when a bad import URL is given --- PluralKit.Bot/Commands/ImportExportCommands.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/PluralKit.Bot/Commands/ImportExportCommands.cs b/PluralKit.Bot/Commands/ImportExportCommands.cs index eb2690f1..4969da82 100644 --- a/PluralKit.Bot/Commands/ImportExportCommands.cs +++ b/PluralKit.Bot/Commands/ImportExportCommands.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using System.Linq; using System.Net.Http; @@ -25,7 +26,17 @@ namespace PluralKit.Bot.Commands { using (var client = new HttpClient()) { - var response = await client.GetAsync(url); + HttpResponseMessage response; + try + { + response = await client.GetAsync(url); + } + catch (InvalidOperationException) + { + // Invalid URL throws this, we just error back out + throw Errors.InvalidImportFile; + } + if (!response.IsSuccessStatusCode) throw Errors.InvalidImportFile; var json = await response.Content.ReadAsStringAsync();