OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.95k stars 6.59k forks source link

[BUG][csharp] missing check for status code 0 - csharp netstandard2.0 #15379

Open kudybab opened 1 year ago

kudybab commented 1 year ago

Generated code in csharp netstandard2.0 is missing check for 0 status code (connection error) samples/client/petstore/csharp/OpenAPIClientNetStandard/src/Org.OpenAPITools/Client/Configuration.cs click here to jump to the Configuration.cs

public static readonly ExceptionFactory DefaultExceptionFactory = (methodName, response) =>
{
    var status = (int)response.StatusCode;
    if (status >= 400)
    {
        return new ApiException(status,
            string.Format("Error calling {0}: {1}", methodName, response.Content),
            response.Content);
    }

    return null;
};

Currently when there is a connection error - the response is null. This is bad because of missing logs and stacktrace. Technically I could wrap it up or use generated {methodName}WithHttpInfoAsync and manually check the status code. Downside - I would need to do it every time I'm using the generated code (for me its multiple apps * multiple methods)

MichaelMay81 commented 8 months ago

This is a duplicate of #15471 .