Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.49k stars 4.82k forks source link

Deserialization Error in RouteMatrixResultResponse When Error String is Returned Instead of Null #45643

Open ChristopherErbs opened 3 months ago

ChristopherErbs commented 3 months ago

Library name and version

Azure Maps Routing API Version: 1.0

Describe the bug

When submitting a Post Route Matrix Request I encountered a deserialization issue with the RouteMatrixResult API when a distance to one of the destinations cannot be resolved. Specifically, the API returns a serialized RouteMatrixResult containing an array of RouteMatrixes. Each RouteMatrix holds a RouteMatrixResultResponse, which in turn contains a RouteLegSummary.

However, when the distance to a destination cannot be resolved, the response field in the RouteMatrixResultResponse is returned as an error string instead of a null value for the RouteMatrixResultResponse object. This causes a deserialization error on the client side, which currently requires manual handling.

Example json:

{
    "formatVersion": "0.0.1",
    "matrix": [
        [
            {
                "statusCode": 400,
                "response": "Engine error while executing route request: MAP_MATCHING_FAILURE: Destination (1, 13.5471)",
                "detailedError": {
                    "message": "Engine error while executing route request: MAP_MATCHING_FAILURE: Destination (1, 13.5471)",
                    "code": "MAP_MATCHING_FAILURE"
                }
            },
            {
                "statusCode": 200,
                "response": {
                    "routeSummary": {
                        "lengthInMeters": 264939,
                        "travelTimeInSeconds": 10394,
                        "trafficDelayInSeconds": 191,
                        "trafficLengthInMeters": 16648,
                        "departureTime": "2024-08-21T09:31:41+02:00",
                        "arrivalTime": "2024-08-21T12:24:55+02:00"
                    }
                }
            },
            {
                "statusCode": 200,
                "response": {
                    "routeSummary": {
                        "lengthInMeters": 305985,
                        "travelTimeInSeconds": 11207,
                        "trafficDelayInSeconds": 191,
                        "trafficLengthInMeters": 16648,
                        "departureTime": "2024-08-21T09:31:41+02:00",
                        "arrivalTime": "2024-08-21T12:38:28+02:00"
                    }
                }
            }
        ]
    ]
}

n the example above, the first entry in the matrix array returns an error string under the response field, which causes a deserialization failure on the client side.

Expected behavior

The response field should return a null value or an appropriately structured error object instead of a plain error string when a distance cannot be resolved. This would prevent deserialization errors and allow the client to handle errors more gracefully.

Actual behavior

Deserialization fails

Reproduction Steps

Steps to Reproduce:

  1. Make a request to the RouteMatrix API with a destination that cannot be resolved.
  2. Observe the response field in the RouteMatrixResultResponse for the destination.
  3. Attempt to deserialize the response into the expected object model.

Environment

.NET6, VS Version 17.10.5

github-actions[bot] commented 3 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @dubiety @jecmenicanikola.

dubiety commented 2 months ago

@ChristopherErbs , thank you for reporting this issue. We'll take a look and try to fix the problem soon!