Skip to content

Commit 339ae55

Browse files
committed
feat: improved error handling
1 parent 029f2b5 commit 339ae55

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# ChangeLog - FOSSology.REST.dotnet
22

3+
## NEXT
4+
* improved error handling.
5+
36
## 1.1.0 (2020-06-25)
47
* supports FOSSology REST API v1.0.16 (FOSSology 3.8.0 built @ 2020/06/19).
58
* new method GetToken().

Fossology.Rest.Dotnet/RestApi.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ---------------------------------------------------------------------------
22
// <copyright file="RestApi.cs" company="Tethys">
3-
// Copyright (C) 2019-2020 T. Graf
3+
// Copyright (C) 2019-2022 T. Graf
44
// </copyright>
55
//
66
// Licensed under the MIT License.
@@ -348,9 +348,22 @@ private static void CheckForErrors(IRestResponse response)
348348
FossologyApiException exception;
349349
try
350350
{
351-
var result = Newtonsoft.Json.JsonConvert.DeserializeObject<Result>(response.Content);
352-
exception = new FossologyApiException(
353-
ErrorCode.RestApiError, (HttpStatusCode)result.Code, result.Message, null);
351+
if (string.IsNullOrEmpty(response.Content))
352+
{
353+
exception = new FossologyApiException(
354+
ErrorCode.RestApiError, response.StatusCode, string.Empty, null);
355+
}
356+
else if (response.Content.ToLower().StartsWith("<html>"))
357+
{
358+
exception = new FossologyApiException(
359+
ErrorCode.RestApiError, response.StatusCode, response.Content, null);
360+
}
361+
else
362+
{
363+
var result = Newtonsoft.Json.JsonConvert.DeserializeObject<Result>(response.Content);
364+
exception = new FossologyApiException(
365+
ErrorCode.RestApiError, (HttpStatusCode)result.Code, result.Message, null);
366+
} // if
354367
}
355368
catch
356369
{

0 commit comments

Comments
 (0)