OpenAPITools / OpenAPITools/openapi-generator

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

Open
#15,379 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with samples/client/petstore/csharp/OpenAPIClientNetStandard/src/Org.OpenAPITools/Client/Configuration.cs and inspect DefaultExceptionFactory's handling of a null response during a connection error. Verify the completed behavior by exercising a connection failure and confirming that the resulting error preserves useful logs and a stack trace.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.