6. Como el saludo no es válido, aborta y genera la response

index.html

const respuesta = await consume(
 submitFormRecibeJson(
  "api/valida.php", formulario))
const json =
 await respuesta.json()
alert(json)

Hace wait esperando response.

api/valida.php

$saludo = recibeTexto("saludo");
$nombre = recibeTexto("nombre");

if (
 $saludo === false
 || $saludo === ""
)
 throw new ProblemDetailsException([
  "status" => BAD_REQUEST,
  "title" => "Falta el saludo.",
  "type" => "/erros/faltasaludo.html"
 ]);

if (
 $nombre === false
 || $nombre === ""
)
 throw new ProblemDetailsException([
  "status" => BAD_REQUEST,
  "title" => "Falta el nombre.",
  "type" => "/errors/faltanombre.html"
 ]);

$resultado = "{$saludo} {$nombre}.";

devuelveJson($resultado);

Response

HTTP/1.1 400 Bad Request Server: openresty
Date: Sun, 17 May 2026 22:01:18 GMT
Content-Type: application/problem+json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
{"title":"Falta el saludo.","type":"\/errors\/faltasaludo.html"}
skip_previous skip_next