Fix review findings: scrub ex.Message from UI, gate 5xx body relay, harmonise ContentApi config key, add CancellationToken to UploadTrack

This commit is contained in:
Daniel Harvey
2026-05-18 15:38:56 -04:00
parent 266086906e
commit 7fd8376f96
4 changed files with 18 additions and 9 deletions
+2 -2
View File
@@ -155,8 +155,8 @@
}
catch (Exception ex)
{
Logger.LogError(ex, "CMS upload failed");
_errorMessage = $"Upload failed: {ex.Message}";
Logger.LogError(ex, "Upload failed in TrackNew");
_errorMessage = "Upload failed. Please try again.";
}
finally
{
@@ -138,7 +138,8 @@ public class TrackController : ControllerBase
[FromForm] string? artist,
[FromForm] string? album,
[FromForm] string? genre,
[FromForm] string? releaseDate)
[FromForm] string? releaseDate,
CancellationToken cancellationToken)
{
_logger.LogInformation("UploadTrack called: trackName={TrackName}, artist={Artist}, size={Size}",
trackName, artist, wav?.Length);
@@ -184,7 +185,7 @@ public class TrackController : ControllerBase
bufferSize: 81920, useAsync: true))
await using (var uploadStream = wav.OpenReadStream())
{
await uploadStream.CopyToAsync(tempStream);
await uploadStream.CopyToAsync(tempStream, cancellationToken);
}
var entity = await _trackService.AddTrackFromWavAsync(
+12 -4
View File
@@ -67,10 +67,10 @@ public class CmsUploadController : ControllerBase
return BadRequest("artist is required");
}
var apiKey = _configuration["ContentApi:ApiKey"];
var apiKey = _configuration["DeepDrftContent:ApiKey"];
if (string.IsNullOrWhiteSpace(apiKey))
{
_logger.LogError("ContentApi:ApiKey is not configured");
_logger.LogError("DeepDrftContent:ApiKey is not configured");
return StatusCode(500, "Content API key is not configured");
}
@@ -118,8 +118,16 @@ public class CmsUploadController : ControllerBase
if (!response.IsSuccessStatusCode)
{
var body = await response.Content.ReadAsStringAsync(cancellationToken);
_logger.LogWarning("Content API rejected upload: {Status} {Body}", (int)response.StatusCode, body);
return StatusCode((int)response.StatusCode, body);
var statusCode = (int)response.StatusCode;
if (statusCode >= 500)
{
_logger.LogError("Content API returned {Status} for upload of {TrackName}: {Body}", statusCode, trackName, body);
return StatusCode(statusCode, "Upload failed on the content server. Please try again.");
}
// 4xx: body is user-friendly validation text from DeepDrftContent — relay as-is.
_logger.LogWarning("Content API rejected upload: {Status} {Body}", statusCode, body);
return StatusCode(statusCode, body);
}
TrackEntity? unpersisted;
+1 -1
View File
@@ -12,7 +12,7 @@
"ApiUrls": {
"ContentApi": "http://localhost:12777/"
},
"ContentApi": {
"DeepDrftContent": {
"ApiKey": "REPLACE_IN_ENV"
},
"ForwardedHeaders": {