Skip to content

Commit 3c0539c

Browse files
committed
fix: fix error handling
1 parent 71f4f4b commit 3c0539c

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

Fossology.Rest.Dotnet/RestApi.cs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -373,38 +373,48 @@ private static void CheckForErrors(RestResponseBase response)
373373
throw new FossologyApiException(ErrorCode.Unauthorized, response.StatusCode);
374374
} // if
375375

376-
var forceError = false;
376+
FossologyApiException exception;
377377
try
378378
{
379379
if (string.IsNullOrEmpty(response.Content))
380380
{
381-
throw new FossologyApiException(
381+
exception = new FossologyApiException(
382382
ErrorCode.RestApiError, response.StatusCode, string.Empty, null);
383-
} // if
384-
385-
if (response.Content.ToLower().StartsWith("<html>"))
386-
{
387-
throw new FossologyApiException(
388-
ErrorCode.RestApiError, response.StatusCode, response.Content, null);
389-
} // if
390-
391-
var result = Newtonsoft.Json.JsonConvert.DeserializeObject<Result>(response.Content);
392-
if (result != null)
383+
}
384+
else
393385
{
394-
throw new FossologyApiException(
395-
ErrorCode.RestApiError, (HttpStatusCode)result.Code, result.Message, null);
386+
if (response.Content.ToLower().StartsWith("<html>"))
387+
{
388+
exception = new FossologyApiException(
389+
ErrorCode.RestApiError, response.StatusCode, response.Content, null);
390+
}
391+
else
392+
{
393+
var result = Newtonsoft.Json.JsonConvert.DeserializeObject<Result>(response.Content);
394+
if (result != null)
395+
{
396+
exception = new FossologyApiException(
397+
ErrorCode.RestApiError, (HttpStatusCode)result.Code, result.Message, null);
398+
}
399+
else
400+
{
401+
exception = new FossologyApiException(
402+
ErrorCode.RestApiError,
403+
response.StatusCode,
404+
"Unable to decode JSON response",
405+
null);
406+
} // if
407+
} // if
396408
} // if
397-
398-
Log.Warn("Unable to decode JSON response");
399409
}
400410
catch
401411
{
402-
forceError = true;
412+
exception = new FossologyApiException(ErrorCode.RestApiError);
403413
} // catch
404414

405-
if (forceError)
415+
if (exception != null)
406416
{
407-
throw new FossologyApiException(ErrorCode.RestApiError);
417+
throw exception;
408418
} // if
409419
} // CheckForErrors()
410420

0 commit comments

Comments
 (0)