proudmonkey / AutoWrapper

A simple, yet customizable global exception handler and Http response wrapper for ASP.NET Core APIs.
MIT License
677 stars 82 forks source link

ApiResponse doesn't return HTTP statusCode #14

Closed trinvh closed 4 years ago

trinvh commented 4 years ago

The issue is the title. The response header is missing a valid HTTP status code. Only occurred with ApiResponse

The example code:

public ApiResponse Register([FromBody] RegisterViewModel model)
{
    return new ApiResponse("Test", model);
}

The logs from docker-compose:

api_1       | info: AutoWrapper.AutoWrapperMiddleware[0]
api_1       |       Request: POST http localhost:5000/api/auth/register  {"full_name":"Hello","username":"sample","email":"email@gmail.com","password":"hello@123"} Responded with [0] in 21ms

In the above output you can see the statusCode responded is [0]

Tested on both v1.0 - 2.1.0 with the same results.

Here is my csproj file in case it's needed:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <RootNamespace>ltmart_api_core</RootNamespace>
    <UserSecretsId>31ef5065-3068-4c82-a978-cab1a5f14bd3</UserSecretsId>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <DockerfileContext>.</DockerfileContext>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
    <PackageReference Include="AutoWrapper.Core" Version="2.1.0" />
    <PackageReference Include="Hangfire.AspNetCore" Version="1.7.7" />
    <PackageReference Include="Hangfire.Postgresql" Version="1.6.3" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="4.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.5" />
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.0.1" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc4" />
  </ItemGroup>

</Project>
proudmonkey commented 4 years ago

@trinvh I've run different scenarios including yours and I can't reproduce the issue. Have you tried testing it without/outside docker? If you test your API using postman for example, does it return the statuscode?

trinvh commented 4 years ago

@proudmonkey I haven't tested yet without docker because I think it will work well with IIS. Didn't try with dotnet run command too, I will give a look when I have a chance.

Yes, I tested it with Postman, also curl -v command, the statusCode was just empty string on Postman

proudmonkey commented 4 years ago

Hi @trinvh - I've retested this again using IIS Express and Kestrel and still I'am not able to replicate the issue. I'm seeing the StatusCodes in both Logs and Response Headers.

proudmonkey commented 4 years ago

Closing this issue now as I can't replicate it. Feel free to reopen if the issue still persist on your side and provide details. Thanks!