Skip to content
Merged
Changes from all 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
42 changes: 13 additions & 29 deletions cs/src/Management/TunnelManagementClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -636,10 +636,19 @@ private string UserLimitsPath
problemDetails.Detail == null)
{
return default;
}

// Enterprise Policies
if (response.Headers.Contains("X-Enterprise-Policy-Failure"))
{
errorMessage = problemDetails!.Title + ": " + problemDetails.Detail;
}
else
{
errorMessage = "Tunnel service error: " +
problemDetails!.Title + " " + problemDetails.Detail;
}

errorMessage = "Tunnel service error: " +
problemDetails!.Title + " " + problemDetails.Detail;

if (problemDetails.Errors != null)
{
foreach (var error in problemDetails.Errors)
Expand Down Expand Up @@ -691,31 +700,7 @@ private string UserLimitsPath
throw new ArgumentException(errorMessage, hrex);

case HttpStatusCode.Unauthorized:
case HttpStatusCode.Forbidden:
// Enterprise Policies
if (response.Headers.Contains("X-Enterprise-Policy-Failure"))
{
var options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
};
var message = response.Content != null ? await response.Content.ReadAsStringAsync() : string.Empty;

ErrorDetails? errorDetails = null;
try
{
errorDetails = JsonSerializer.Deserialize<ErrorDetails>(message, options);
}
catch (JsonException)
{
// If deserialization fails, it means the message is not in JSON format.
// In this case, use the message directly as the error message.
}

// Use the deserialized error detail if available, otherwise use the raw message.
errorMessage = errorDetails?.Detail ?? message;
}

case HttpStatusCode.Forbidden:
var ex = new UnauthorizedAccessException(errorMessage, hrex);

// The HttpResponseHeaders.WwwAuthenticate property does not correctly
Expand Down Expand Up @@ -761,7 +746,6 @@ private class ErrorDetails
{
public string? Message { get; set; }
public string? StackTrace { get; set; }
public string? Detail { get; set; }
}

/// <inheritdoc/>
Expand Down