diff --git a/Octokit.Tests/Exceptions/ApiExceptionTests.cs b/Octokit.Tests/Exceptions/ApiExceptionTests.cs index bad38f72..7daa4aec 100644 --- a/Octokit.Tests/Exceptions/ApiExceptionTests.cs +++ b/Octokit.Tests/Exceptions/ApiExceptionTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Net; #if !NO_SERIALIZABLE @@ -141,6 +142,16 @@ namespace Octokit.Tests.Exceptions Assert.NotNull(stringRepresentation); } + [Fact] + public void DoesNotThrowIfContentTypeIsNotDefined() + { + var response = CreateResponse(HttpStatusCode.GatewayTimeout, null, new Dictionary(), null); + + var exception = new ApiException(response); + var stringRepresentation = exception.ToString(); + Assert.NotNull(stringRepresentation); + } + [Fact] public void DoesNotPrintImageContent() { diff --git a/Octokit/Exceptions/ApiException.cs b/Octokit/Exceptions/ApiException.cs index 4dd08d27..9c997136 100644 --- a/Octokit/Exceptions/ApiException.cs +++ b/Octokit/Exceptions/ApiException.cs @@ -200,7 +200,7 @@ namespace Octokit { get { - return HttpResponse != null + return HttpResponse?.ContentType != null && !HttpResponse.ContentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase) && HttpResponse.Body is string ? (string)HttpResponse.Body : string.Empty;