Skip to content

Commit 1fde08e

Browse files
committed
fix the response creation after migration to dotnet 7
1 parent 0020a25 commit 1fde08e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/CZ.Azure.FileExchange.Api/GenerateSas.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public GenerateSas(ILogger<GenerateSas> log) =>
2525
[OpenApiOperation(operationId: "Run")]
2626
[OpenApiParameter(name: "filecode", In = ParameterLocation.Query, Required = false, Type = typeof(string), Description = "The **code** parameter, that represent to get read access to stored files")]
2727
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "text/plain", bodyType: typeof(string), Description = "The OK response")]
28-
public async Task<IActionResult> Run(
28+
public async Task<HttpResponseData> Run(
2929
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequestData req)
3030
{
3131
this.logger.LogInformation("Start generating SaS");
@@ -49,10 +49,17 @@ public async Task<IActionResult> Run(
4949
if (uri == null)
5050
{
5151
this.logger.LogError("Failed to generate the Sas token");
52-
return new BadRequestObjectResult(new StringContent("Failed to greate SaS token to upload your files. Please try again."));
52+
var badResponse = req.CreateResponse(HttpStatusCode.BadRequest);
53+
var badContent = new StringContent("Failed to greate SaS token to upload your files. Please try again.");
54+
badResponse.Headers.Add("Content-Type", badContent.Headers.ContentType?.ToString());
55+
badResponse.WriteString(await badContent.ReadAsStringAsync());
56+
return badResponse;
5357
}
54-
55-
return new OkObjectResult(uri.ToString());
58+
var okResponse = req.CreateResponse(HttpStatusCode.OK);
59+
var content = new StringContent(uri.ToString());
60+
okResponse.Headers.Add("Content-Type", content.Headers.ContentType?.ToString());
61+
okResponse.WriteString(await content.ReadAsStringAsync());
62+
return okResponse;
5663
}
5764

5865
private static string GetEnvironmentVariable(string name) =>

0 commit comments

Comments
 (0)