Skip to content

Commit 9b9472b

Browse files
Managed Challenges: report failed update attempts back to client
1 parent 3e1deea commit 9b9472b

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/Certify.Providers/DNS/CertifyManaged/DnsProviderCertifyManaged.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Certify.Models.Hub;
88
using Certify.Models.Plugins;
99
using Certify.Models.Providers;
10+
using Certify.Models.Util;
1011
using Certify.Plugins;
1112
using Certify.SharedUtils;
1213
using Newtonsoft.Json;
@@ -147,7 +148,36 @@ public async Task<ActionResult> CreateRecord(DnsRecord request)
147148
}
148149
else
149150
{
150-
return new ActionResult { IsSuccess = false, Message = $"Update failed [{result.StatusCode}] : check API URL is valid [{apiUri}], auth credentials are correct and authorised for a matching managed challenge." };
151+
var responseJson = await result.Content.ReadAsStringAsync();
152+
153+
// Try to parse as ActionResult first (if API returns structured error)
154+
try
155+
{
156+
var errorResult = JsonConvert.DeserializeObject<ProblemDetails>(responseJson);
157+
if (errorResult != null && !string.IsNullOrWhiteSpace(errorResult.Detail))
158+
{
159+
return new ActionResult
160+
{
161+
IsSuccess = false,
162+
Message = $"Update failed [{result.StatusCode}]: {errorResult.Detail}"
163+
};
164+
}
165+
}
166+
catch
167+
{
168+
// If JSON parsing fails, fall back to raw response
169+
}
170+
171+
// Fallback to including raw response content
172+
var errorMessage = string.IsNullOrWhiteSpace(responseJson)
173+
? "No additional error details available"
174+
: responseJson;
175+
176+
return new ActionResult
177+
{
178+
IsSuccess = false,
179+
Message = $"Update failed [{result.StatusCode}]: {errorMessage}. Check API URL is valid [{apiUri}], auth credentials are correct and authorised for a matching managed challenge."
180+
};
151181
}
152182
}
153183
catch (Exception exp)

src/Certify.Server/Certify.Server.Hub.Api/Controllers/v1/ManagedChallengeController.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,22 @@ public ManagedChallengeController(ILogger<ManagedChallengeController> logger, IC
3636
[Route("request")]
3737
[AllowAnonymous]
3838
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(Certify.Models.Config.ActionResult))]
39+
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status502BadGateway)]
3940
public async Task<IActionResult> PerformManagedChallenge(ManagedChallengeRequest request)
4041
{
4142
var result = await _client.PerformManagedChallenge(request, null);
42-
return new OkObjectResult(result);
43+
44+
if (result.IsSuccess)
45+
{
46+
return new OkObjectResult(result);
47+
}
48+
else
49+
{
50+
return Problem(
51+
detail: result.Message,
52+
statusCode: StatusCodes.Status502BadGateway
53+
);
54+
}
4355
}
4456

4557
/// <summary>

0 commit comments

Comments
 (0)