Skip to content

Commit

Permalink
Merge pull request #47 from lorddev/issue/46
Browse files Browse the repository at this point in the history
Issue #46 add check for null and set error code
  • Loading branch information
anthony-murphy-lrn authored Mar 12, 2024
2 parents bf4f299 + 997bf60 commit ef456ca
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions LearnositySDK/Request/Remote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.IO;
using LearnositySDK.Utils;
using System.Diagnostics;
using System.Threading;

namespace LearnositySDK.Request
{
Expand Down Expand Up @@ -178,10 +179,11 @@ private Remote request(string url, string post = null, JsonObject options = null
}
}

Stopwatch timer = new Stopwatch();
timer.Start();

try
{
Stopwatch timer = new Stopwatch();
timer.Start();
using (this.result = this.hr.GetResponse())
{
using (StreamReader sr = new StreamReader(this.result.GetResponseStream()))
Expand All @@ -190,23 +192,27 @@ private Remote request(string url, string post = null, JsonObject options = null
}
}
this.status = "200";
timer.Stop();
this.time = timer.Elapsed.Seconds;
}
catch (WebException e)
{
using (this.result = e.Response)
{
using (StreamReader sr = new StreamReader(this.result.GetResponseStream()))
if (this.result != null)
{
this.responseBody = sr.ReadToEnd();
using (StreamReader sr = new StreamReader(this.result.GetResponseStream()))
{
this.responseBody = sr.ReadToEnd();
}
}
}
this.status = e.Status.ToString();
this.errorCode = this.status;
this.errorMessage = e.Message;
}

timer.Stop();
this.time = timer.Elapsed.Seconds;

this.process();
return this;
}
Expand Down

0 comments on commit ef456ca

Please sign in to comment.