diff --git a/src/libs/AutoSDK/Models/EndPointResponse.cs b/src/libs/AutoSDK/Models/EndPointResponse.cs index 4c929f8fd0..4b5e000a54 100644 --- a/src/libs/AutoSDK/Models/EndPointResponse.cs +++ b/src/libs/AutoSDK/Models/EndPointResponse.cs @@ -17,6 +17,7 @@ TypeData Type public bool Is4XX => StatusCode.StartsWith("4", StringComparison.OrdinalIgnoreCase); public bool Is5XX => StatusCode.StartsWith("5", StringComparison.OrdinalIgnoreCase); public bool IsDefault => StatusCode == "default"; + public bool IsPattern => StatusCode.Contains("XX"); public static EndPointResponse Default => new( StatusCode: "200", diff --git a/src/libs/AutoSDK/Sources/Sources.Methods.cs b/src/libs/AutoSDK/Sources/Sources.Methods.cs index 56b18178ba..c3f5e8b1bb 100644 --- a/src/libs/AutoSDK/Sources/Sources.Methods.cs +++ b/src/libs/AutoSDK/Sources/Sources.Methods.cs @@ -392,7 +392,14 @@ public static string GenerateResponse( _ => "ByteArray", }; - var errors = endPoint.Settings.GenerateExceptions ? endPoint.ErrorResponses.Select(x => $@" + // If a response range is defined using an explicit code, the explicit code definition takes precedence over the range definition for that code + var orderedErrorResponses = endPoint.ErrorResponses + .Where(x => x is { IsPattern: false, IsDefault: false }) + .Concat(endPoint.ErrorResponses.Where(x => x is { IsPattern: true, IsDefault: false })) + .Concat(endPoint.ErrorResponses.Where(x => x.IsDefault)) + .ToArray(); + + var errors = endPoint.Settings.GenerateExceptions ? orderedErrorResponses.Select(x => $@" // {x.Description.Replace('\n', ' ').Replace('\r', ' ')} {(x.IsDefault ? @" if (!__response.IsSuccessStatusCode)" : @$"