From a0c155067e39e9787fc826df1b447720c76e937a Mon Sep 17 00:00:00 2001 From: catcherwong Date: Tue, 11 Jul 2023 04:29:47 +0000 Subject: [PATCH] fix http status code (#498) Signed-off-by: catcherwong --- .../Functions/UrlArchive.cs | 2 +- .../Functions/UrlClickStatsByDay.cs | 2 +- .../Functions/UrlCreate.cs | 8 ++++---- .../Functions/UrlList.cs | 2 +- .../Functions/UrlUpdate.cs | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Cloud5mins.ShortenerTools.Functions/Functions/UrlArchive.cs b/src/Cloud5mins.ShortenerTools.Functions/Functions/UrlArchive.cs index 0e35338a..e57725f0 100644 --- a/src/Cloud5mins.ShortenerTools.Functions/Functions/UrlArchive.cs +++ b/src/Cloud5mins.ShortenerTools.Functions/Functions/UrlArchive.cs @@ -86,7 +86,7 @@ public async Task Run( { _logger.LogError(ex, "An unexpected error was encountered."); var badRequest = req.CreateResponse(HttpStatusCode.BadRequest); - await badRequest.WriteAsJsonAsync(new { ex.Message }); + await badRequest.WriteAsJsonAsync(new { ex.Message }, badRequest.StatusCode); return badRequest; } diff --git a/src/Cloud5mins.ShortenerTools.Functions/Functions/UrlClickStatsByDay.cs b/src/Cloud5mins.ShortenerTools.Functions/Functions/UrlClickStatsByDay.cs index e64299e5..7b5d30e3 100644 --- a/src/Cloud5mins.ShortenerTools.Functions/Functions/UrlClickStatsByDay.cs +++ b/src/Cloud5mins.ShortenerTools.Functions/Functions/UrlClickStatsByDay.cs @@ -96,7 +96,7 @@ public async Task Run( { _logger.LogError(ex, "An unexpected error was encountered."); var badRequest = req.CreateResponse(HttpStatusCode.BadRequest); - await badRequest.WriteAsJsonAsync(new { Message = $"{ex.Message}" }); + await badRequest.WriteAsJsonAsync(new { Message = $"{ex.Message}" }, badRequest.StatusCode); return badRequest; } diff --git a/src/Cloud5mins.ShortenerTools.Functions/Functions/UrlCreate.cs b/src/Cloud5mins.ShortenerTools.Functions/Functions/UrlCreate.cs index 80373f9d..8a1cad12 100644 --- a/src/Cloud5mins.ShortenerTools.Functions/Functions/UrlCreate.cs +++ b/src/Cloud5mins.ShortenerTools.Functions/Functions/UrlCreate.cs @@ -79,7 +79,7 @@ ExecutionContext context if (string.IsNullOrWhiteSpace(input.Url)) { var badResponse = req.CreateResponse(HttpStatusCode.BadRequest); - await badResponse.WriteAsJsonAsync(new { Message = "The url parameter can not be empty." }); + await badResponse.WriteAsJsonAsync(new { Message = "The url parameter can not be empty." }, badResponse.StatusCode); return badResponse; } @@ -87,7 +87,7 @@ ExecutionContext context if (!Uri.IsWellFormedUriString(input.Url, UriKind.Absolute)) { var badResponse = req.CreateResponse(HttpStatusCode.BadRequest); - await badResponse.WriteAsJsonAsync(new { Message = $"{input.Url} is not a valid absolute Url. The Url parameter must start with 'http://' or 'http://'." }); + await badResponse.WriteAsJsonAsync(new { Message = $"{input.Url} is not a valid absolute Url. The Url parameter must start with 'http://' or 'http://'." }, badResponse.StatusCode); return badResponse; } @@ -106,7 +106,7 @@ ExecutionContext context if (await stgHelper.IfShortUrlEntityExist(newRow)) { var badResponse = req.CreateResponse(HttpStatusCode.Conflict); - await badResponse.WriteAsJsonAsync(new { Message = "This Short URL already exist." }); + await badResponse.WriteAsJsonAsync(new { Message = "This Short URL already exist." }, badResponse.StatusCode); return badResponse; } } @@ -127,7 +127,7 @@ ExecutionContext context _logger.LogError(ex, "An unexpected error was encountered."); var badResponse = req.CreateResponse(HttpStatusCode.BadRequest); - await badResponse.WriteAsJsonAsync(new { ex.Message }); + await badResponse.WriteAsJsonAsync(new { ex.Message }, badResponse.StatusCode); return badResponse; } diff --git a/src/Cloud5mins.ShortenerTools.Functions/Functions/UrlList.cs b/src/Cloud5mins.ShortenerTools.Functions/Functions/UrlList.cs index 97c78e81..b993fec9 100644 --- a/src/Cloud5mins.ShortenerTools.Functions/Functions/UrlList.cs +++ b/src/Cloud5mins.ShortenerTools.Functions/Functions/UrlList.cs @@ -65,7 +65,7 @@ public async Task Run( { _logger.LogError(ex, "An unexpected error was encountered."); var badres = req.CreateResponse(HttpStatusCode.BadRequest); - await badres.WriteAsJsonAsync(new { ex.Message }); + await badres.WriteAsJsonAsync(new { ex.Message }, badres.StatusCode); return badres; } diff --git a/src/Cloud5mins.ShortenerTools.Functions/Functions/UrlUpdate.cs b/src/Cloud5mins.ShortenerTools.Functions/Functions/UrlUpdate.cs index 7d839e2c..8a4c6332 100644 --- a/src/Cloud5mins.ShortenerTools.Functions/Functions/UrlUpdate.cs +++ b/src/Cloud5mins.ShortenerTools.Functions/Functions/UrlUpdate.cs @@ -88,7 +88,7 @@ ExecutionContext context if (string.IsNullOrWhiteSpace(input.Url)) { var badRequest = req.CreateResponse(HttpStatusCode.BadRequest); - await badRequest.WriteAsJsonAsync(new { Message = "The url parameter can not be empty." }); + await badRequest.WriteAsJsonAsync(new { Message = "The url parameter can not be empty." }, badRequest.StatusCode); return badRequest; } @@ -96,7 +96,7 @@ ExecutionContext context if (!Uri.IsWellFormedUriString(input.Url, UriKind.Absolute)) { var badRequest = req.CreateResponse(HttpStatusCode.BadRequest); - await badRequest.WriteAsJsonAsync(new { Message = $"{input.Url} is not a valid absolute Url. The Url parameter must start with 'http://' or 'http://'." }); + await badRequest.WriteAsJsonAsync(new { Message = $"{input.Url} is not a valid absolute Url. The Url parameter must start with 'http://' or 'http://'." }, badRequest.StatusCode); return badRequest; } @@ -112,7 +112,7 @@ ExecutionContext context _logger.LogError(ex, "An unexpected error was encountered."); var badRequest = req.CreateResponse(HttpStatusCode.BadRequest); - await badRequest.WriteAsJsonAsync(new { ex.Message }); + await badRequest.WriteAsJsonAsync(new { ex.Message }, badRequest.StatusCode); return badRequest; }