Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions codegen/layouts/partials/route-methods.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ requestOptions.Data = request;
{{#if isVoid}}
_seam.Post<object>("{{path}}", requestOptions);
{{else}}
return _seam.Post<{{responseTypeArg}}>("{{path}}", requestOptions).Data.{{returnProp}};
return _seam.Post<{{responseTypeArg}}>("{{path}}", requestOptions).EnsureData("{{path}}").{{returnProp}};
{{/if}}
}

Expand All @@ -28,7 +28,7 @@ requestOptions.Data = request;
{{#if isVoid}}
await _seam.PostAsync<object>("{{path}}", requestOptions);
{{else}}
return (await _seam.PostAsync<{{responseTypeArg}}>("{{path}}", requestOptions)).Data.{{returnProp}};
return (await _seam.PostAsync<{{responseTypeArg}}>("{{path}}", requestOptions)).EnsureData("{{path}}").{{returnProp}};
{{/if}}
}

Expand Down
50 changes: 50 additions & 0 deletions output/csharp/src/Seam.Test/Client/ApiResponseTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
namespace Seam.Test;

using System.Net;
using Seam.Client;

public class ApiResponseTests
{
[Fact]
public void EnsureDataReturnsDataWhenPresent()
{
var data = new Api.Locks.ListResponse(devices: new List<Model.Device>());
var response = new ApiResponse<Api.Locks.ListResponse>(HttpStatusCode.OK, data, "{}");

Assert.Same(data, response.EnsureData("/locks/list"));
}

[Fact]
public void EnsureDataThrowsSeamExceptionWhenDataIsNull()
{
var headers = new Multimap<string, string> { { "seam-request-id", "req-123" } };
var response = new ApiResponse<Api.Locks.ListResponse>(
HttpStatusCode.OK,
headers,
null!,
"<html>unexpected body</html>"
);

var exception = Assert.Throws<SeamException>(() => response.EnsureData("/locks/list"));

Assert.Equal(200, exception.ErrorCode);
Assert.Contains("/locks/list", exception.Message);
Assert.Contains("HTTP 200", exception.Message);
Assert.Equal("<html>unexpected body</html>", exception.ErrorContent);
Assert.Equal(headers, exception.Headers);
}

[Fact]
public void EnsureDataIncludesErrorTextInMessageWhenSet()
{
var response = new ApiResponse<Api.Locks.ListResponse>(HttpStatusCode.OK, null!, "not json")
{
ErrorText = "Error deserializing response",
};

var exception = Assert.Throws<SeamException>(() => response.EnsureData("/locks/list"));

Assert.Contains("Error deserializing response", exception.Message);
Assert.Equal("not json", exception.ErrorContent);
}
}
34 changes: 22 additions & 12 deletions output/csharp/src/Seam/Api/AccessCodes.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 17 additions & 10 deletions output/csharp/src/Seam/Api/AccessGrants.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions output/csharp/src/Seam/Api/AccessGroupsAcs.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading