Skip to content

Commit

Permalink
parse error msg and update version (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
HzANut authored Jun 13, 2023
1 parent 25b8ddd commit 5c3bc1a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion Moesif.Api/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Moesif.Api.Exceptions;
using System.IO;
using System.Text;
using Newtonsoft.Json.Linq;

namespace Moesif.Api.Controllers
{
Expand Down Expand Up @@ -62,7 +63,9 @@ internal void ValidateResponse(HttpResponse _response, HttpContext _context)
Byte[] bytes = new byte[body.Length];
body.Position = 0;
body.Read(bytes, 0, (int)body.Length);
bodyData = Encoding.ASCII.GetString(bytes);
string bodyStr = Encoding.UTF8.GetString(bytes);
JObject jsonErr = JObject.Parse(bodyStr);
bodyData = (string)jsonErr["moesif_error"]["msg"];

This comment has been minimized.

Copy link
@CodeYouMust

CodeYouMust Jun 13, 2023

Member

@XinyuLuan in some error case/statuses.. it is possible that the body is not json (because moesif api may not even reach it).. in that case, json parsing will throw an exception and the exception will be silently absorbed below.. in line 71?
maybe we want to return the non-json body if we cannot extract ["moesif_error"]["msg"] ?

This comment has been minimized.

Copy link
@HzANut

HzANut Jun 13, 2023

Author Contributor

Thanks @CodeYouMust, we are putting this way is because the validResponse is only for moesif api calls. so we will get the error from moesif, unless we return different schema. But in case of that, @praves77 do we want to return the non-json body like @CodeYouMust suggested when we catch the exception. So we don't silently absorb any logs.

This comment has been minimized.

Copy link
@praves77

praves77 Jun 13, 2023

Contributor

After merging we realized that. One possibility was :
bodyData = bodyStr;
bodyData = (string)jsonErr["moesif_error"]["msg"];

But we thought non-200 error will be thrown by Moesif (following standard error response schema) except the timeout.

}
}
catch (Exception) { };
Expand Down
6 changes: 3 additions & 3 deletions Moesif.Api/Moesif.Api.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>Moesif.Api</id>
<version>2.0.6</version>
<version>2.0.7</version>
<title>MoesifApi</title>
<authors>Moesif</authors>
<owners>Moesif</owners>
Expand All @@ -18,11 +18,11 @@
<tags>azure web app moesif API analytics insights debug debugging log logging apm performance monitor monitoring restful rest graphql ethereum web3 json-rpc soap net microsoft</tags>
<dependencies>
<group targetFramework="netstandard2.0">
<dependency id="Newtonsoft.Json" version="9.0.1" />
<dependency id="Newtonsoft.Json" version="13.0.2" />
<dependency id="Unirest-APIMATIC" version="1.0.1.26" />
</group>
<group targetFramework="net45">
<dependency id="Newtonsoft.Json" version="9.0.1" />
<dependency id="Newtonsoft.Json" version="13.0.2" />
<dependency id="Unirest-APIMATIC" version="1.0.1.26" />
</group>
</dependencies>
Expand Down
4 changes: 2 additions & 2 deletions Moesif.Api/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.6")]
[assembly: AssemblyFileVersion("2.0.6")]
[assembly: AssemblyVersion("2.0.7")]
[assembly: AssemblyFileVersion("2.0.7")]

0 comments on commit 5c3bc1a

Please sign in to comment.