Skip to content

Commit

Permalink
fix: Now error responses have order.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Nov 12, 2024
1 parent 9624480 commit 067f548
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/libs/AutoSDK/Models/EndPointResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 8 additions & 1 deletion src/libs/AutoSDK/Sources/Sources.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)" : @$"
Expand Down

0 comments on commit 067f548

Please sign in to comment.