Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
changes:
- section: "Bugs Fixed"
description: "Fixed `azureterraform_azapi_get` returning `500 InternalServerError` for invalid resource type or API version inputs. The tool now returns `400 BadRequest` with an actionable message, enabling agents to auto-correct and retry with valid inputs."
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.IO;
using System.Net;
using Azure.Mcp.Tools.AzureTerraform.Models;
using Azure.Mcp.Tools.AzureTerraform.Options;
Expand Down Expand Up @@ -55,6 +56,12 @@ protected override AzApiDocsOptions BindOptions(ParseResult parseResult)
};
}

protected override HttpStatusCode GetStatusCode(Exception ex) => ex switch
{
InvalidDataException => HttpStatusCode.BadRequest,
_ => base.GetStatusCode(ex)
};

public override async Task<CommandResponse> ExecuteAsync(
CommandContext context,
ParseResult parseResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,19 @@ public sealed class AzApiDocsService : IAzApiDocsService
public AzApiDocsResult GetDocumentation(string resourceTypeName, string? apiVersion = null)
{
var serviceProvider = s_schemaServiceProvider.Value;
TypesDefinitionResult typesResult = SchemaGenerator.GetResourceTypeDefinitions(serviceProvider, resourceTypeName, apiVersion);
Comment thread
vcolin7 marked this conversation as resolved.
TypesDefinitionResult typesResult;
try
{
typesResult = SchemaGenerator.GetResourceTypeDefinitions(serviceProvider, resourceTypeName, apiVersion);
}
catch (InvalidDataException)
{
throw;
}
catch (Exception ex)
{
throw new InvalidDataException(ex.Message, ex);
}
Comment thread
vcolin7 marked this conversation as resolved.
Outdated
List<ComplexType> complexTypes = SchemaGenerator.GetResponse(typesResult);

string resolvedApiVersion = typesResult.ApiVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public async Task ExecuteAsync_ServiceThrows_HandlesException()

var response = await ExecuteCommandAsync("--resource-type", "Microsoft.Fake/nonexistent");

Assert.NotEqual(HttpStatusCode.OK, response.Status);
Assert.Equal(HttpStatusCode.BadRequest, response.Status);
}

[Theory]
Expand Down