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

index.html

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

Hace wait esperando response.

srv/valida.php

$saludo = recibeTexto("saludo");
$nombre = recibeTexto("nombre");
if (
 $saludo === false
 || $saludo === ""
) {
 throw new ProblemDetails(
  status: ProblemDetails::BadRequest,
  type: "/errors/faltasaludo.html",
  title: "Falta el saludo.",
 );
}
if (
 $nombre === false
 || $nombre === ""
) {
 throw new ProblemDetails(
  status: ProblemDetails::BadRequest,
  type: "/errors/faltanombre.html",
  title: "Falta el nombre.",
 );
}
$resultado =
 "{$saludo} {$nombre}.";
devuelveJson($resultado);

Response

HTTP/1.1 400 Bad Request Server: openresty
Date: Fri, 02 May 2025 13:53:21 GMT
Content-Type: application/problem+json
Transfer-Encoding: chunked
Connection: keep-alive
{"title":"Falta el saludo.","type":"\/errors\/faltasaludo.html"}
skip_previous skip_next