Repository: microsoft/kiota (csharp)

Issue:
Cannot find name 'createStringFromDiscriminatorValue' when generating typescript
```
kiota --version
1.10.1+fa5da75b8b4f362d821032021bc5bfcf063cb522
```

openapi yaml like:

```
openapi: '3.0.2'
info:
  title: JSONPlaceholder
  version: '1.0'
servers:
  - url: https://jsonplaceholder.typicode.com/

paths:
  /api/download/{blobId}:
    parameters:
    - in: path
      name: blobId
      schema:
        type: string
      required: true
      description: BLOB ID
    get:
      summary: download temporary BLOB
      responses:
        '302':
          description: Found the BLOB and returned a signed URL to download it.
          headers:
            Location:
              required: true
              schema:
                type: string
        '400':
          description: Invalid ID
        '403':
          description: Not allowed
        '404':
          description: not found.
        default:
          description: General Error
          content:
            application/json:
              schema:
                type: string
```

the generated code is using `createStringFromDiscriminatorValue` which is not imported and not found in the `item/index.ts`

```
    public get(requestConfiguration?: RequestConfiguration<object> | undefined) : Promise<ArrayBuffer | undefined> {
        const requestInfo = this.toGetRequestInformation(
            requestConfiguration
        );
        const errorMapping = {
            "4XX": createStringFromDiscriminatorValue,
            "5XX": createStringFromDiscriminatorValue,
        } as Record<string, ParsableFactory<Parsable>>;
        return this.requestAdapter.sendPrimitiveAsync<ArrayBuffer>(requestInfo, "ArrayBuffer", errorMapping);
    }
```

I guess the correct one is createMessageFromDiscriminatorValue

Pull request:
fixes #4018

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 96ad1f37a3..6981a71d6e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed
 
+- Fixed a bug where scalar error mappings would be generated even though it's not supported by the http request adapter. [#4018](https://github.com/microsoft/kiota/issues/4018)
+
 ## [1.10.1] - 2024-01-12
 
 ### Added
diff --git a/src/Kiota.Builder/KiotaBuilder.cs b/src/Kiota.Builder/KiotaBuilder.cs
index 7f37bc05bd..bd618c9e94 100644
--- a/src/Kiota.Builder/KiotaBuilder.cs
+++ b/src/Kiota.Builder/KiotaBuilder.cs
@@ -1283,15 +1283,14 @@ private void AddErrorMappingToExecutorMethod(OpenApiUrlTreeNode currentNode, Ope
                 : modelsNamespace;
             var errorType = CreateModelDeclarations(currentNode, errorSchema, operation, parentElement, $"{errorCode}Error", response: response);
             if (errorType is CodeType codeType &&
-                codeType.TypeDefinition is CodeClass codeClass &&
-                !codeClass.IsErrorDefinition)
+                codeType.TypeDefinition is CodeClass codeClass)
             {
-                codeClass.IsErrorDefinition = true;
+                if (!codeClass.IsErrorDefinition)
+                    codeClass.IsErrorDefinition = true;
+                executorMethod.AddErrorMapping(errorCode, errorType);
             }
-            if (errorType is null)
-                logger.LogWarning("Could not create error type for {Error} in {Operation}", errorCode, operation.OperationId);
             else
-                executorMethod.AddErrorMapping(errorCode, errorType);
+                logger.LogWarning("Could not create error type for {Error} in {Operation}", errorCode, operation.OperationId);
         }
     }
     private (CodeTypeBase?, CodeTypeBase?) GetExecutorMethodReturnType(OpenApiUrlTreeNode currentNode, OpenApiSchema? schema, OpenApiOperation operation, CodeClass parentClass, OperationType operationType)


Test patch:
diff --git a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs
index 615da912cb..8521c78141 100644
--- a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs
+++ b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs
@@ -2037,6 +2037,19 @@ public void AddsErrorMapping()
                                 }
                             }
                         },
+                        ["402"] = new OpenApiResponse
+                        {
+                            Content =
+                            {
+                                ["application/json"] = new OpenApiMediaType
+                                {
+                                    Schema = new OpenApiSchema
+                                    {
+                                        Type = "string"
+                                    }
+                                }
+                            }
+                        },
                         ["401"] = new OpenApiResponse
                         {
                             Content =
@@ -2083,6 +2096,7 @@ public void AddsErrorMapping()
         var keys = executorMethod.ErrorMappings.Select(x => x.Key).ToHashSet();
         Assert.Contains("4XX", keys);
         Assert.Contains("401", keys);
+        Assert.DoesNotContain("402", keys);
         Assert.Contains("5XX", keys);
         var errorType401 = codeModel.FindChildByName<CodeClass>("tasks401Error");
         Assert.NotNull(errorType401);