From 8e164be0d7cacf5925e0b8f04ca0d366c52dc520 Mon Sep 17 00:00:00 2001 From: Felipe Cotti Date: Sat, 5 Oct 2024 10:42:33 -0300 Subject: [PATCH] Turns out it answers 204 in production, so let's fix that. Also, let's improve example.html's response handling. --- .../Guestbooky.API/Controllers/MessageController.cs | 2 +- src/input-example/example.html | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Guestbooky/Guestbooky.API/Controllers/MessageController.cs b/src/Guestbooky/Guestbooky.API/Controllers/MessageController.cs index 832d390..f9b1afa 100644 --- a/src/Guestbooky/Guestbooky.API/Controllers/MessageController.cs +++ b/src/Guestbooky/Guestbooky.API/Controllers/MessageController.cs @@ -23,7 +23,7 @@ public class MessageController : ControllerBase } [HttpPost] - [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status403Forbidden)] [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)] public async Task Insert([FromBody] InsertMessageRequestDto message, CancellationToken token) diff --git a/src/input-example/example.html b/src/input-example/example.html index 69eced1..0f62e4d 100644 --- a/src/input-example/example.html +++ b/src/input-example/example.html @@ -141,13 +141,12 @@ document body: JSON.stringify(data), }); - const result = await response.json(); - - if (response.ok) { + if (response.status >= 200 && response.status <= 299) { alert("Note added successfully!"); this.reset(); // Clear the form fields } else { - alert(result.errorMessage); + const problem = await response.json(); + alert(problem); } });