Skip to content
Snippets Groups Projects
Commit 59a176df authored by Daniel Andrášik's avatar Daniel Andrášik
Browse files

- fix test

- fix error handling
parent 6accd71c
No related branches found
No related tags found
No related merge requests found
...@@ -119,29 +119,23 @@ namespace SDK ...@@ -119,29 +119,23 @@ namespace SDK
protected async Task HandleError(HttpResponseMessage response) protected async Task HandleError(HttpResponseMessage response)
{ {
var stringContent = await response.Content.ReadAsStringAsync(); var stringContent = await response.Content.ReadAsStringAsync();
try
{ switch (response.StatusCode)
switch (response.StatusCode)
{
case System.Net.HttpStatusCode.BadRequest:
case System.Net.HttpStatusCode.Unauthorized:
case System.Net.HttpStatusCode.PaymentRequired:
case System.Net.HttpStatusCode.Forbidden:
case System.Net.HttpStatusCode.NotFound:
case System.Net.HttpStatusCode.MethodNotAllowed:
case System.Net.HttpStatusCode.InternalServerError:
var prettyJson = JsonSerializer.Serialize(stringContent, new JsonSerializerOptions()
{
WriteIndented = true
});
throw new ServerResponseException(prettyJson);
default:
throw new ServerResponseException(stringContent);
}
}
catch (Exception)
{ {
throw new ServerResponseException(stringContent); case System.Net.HttpStatusCode.BadRequest:
case System.Net.HttpStatusCode.Unauthorized:
case System.Net.HttpStatusCode.PaymentRequired:
case System.Net.HttpStatusCode.Forbidden:
case System.Net.HttpStatusCode.NotFound:
case System.Net.HttpStatusCode.MethodNotAllowed:
case System.Net.HttpStatusCode.InternalServerError:
var prettyJson = JsonSerializer.Serialize(stringContent, new JsonSerializerOptions()
{
WriteIndented = true
});
throw new ServerResponseException(prettyJson);
default:
throw new ServerResponseException(stringContent);
} }
} }
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
<AssemblyVersion>2021.6.28.25</AssemblyVersion> <AssemblyVersion>2021.6.28.25</AssemblyVersion>
<FileVersion>2021.6.28.25</FileVersion> <FileVersion>2021.6.28.25</FileVersion>
<Version>4.2.0</Version> <Version>4.2.1</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup> </PropertyGroup>
......
...@@ -17,7 +17,7 @@ using SDK.Exceptions; ...@@ -17,7 +17,7 @@ using SDK.Exceptions;
namespace Test namespace Test
{ {
[TestClass] [TestClass]
public class AreaTest public class DeviceTest
{ {
protected const string URL = "http://localhost:8000"; protected const string URL = "http://localhost:8000";
private const string PATH_BASE = "/api/v3/devices"; private const string PATH_BASE = "/api/v3/devices";
...@@ -60,9 +60,9 @@ namespace Test ...@@ -60,9 +60,9 @@ namespace Test
Message = "Error" Message = "Error"
}; };
server.Reset();
server.Given(Request.Create().WithPath(PATH_BASE).UsingGet()) server.Given(Request.Create().WithPath(PATH_BASE).UsingGet())
.RespondWith(Response.Create().WithStatusCode(400).WithBodyAsJson(bodyContent)); .RespondWith(Response.Create().WithStatusCode(400).WithBodyAsJson(bodyContent));
await Assert.ThrowsExceptionAsync<ServerResponseException>(async () => await devkitConnector.GetDevices()); await Assert.ThrowsExceptionAsync<ServerResponseException>(async () => await devkitConnector.GetDevices());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment