Errors
HttpError
Throw HttpError to return a status and a message
import { , } from "@senrijs/senri";
const = ();
.("/secret", () => {
throw new (403, "You cannot see this"); // the message is sent to the client as is
});curl -i http://localhost:3927/secret
# HTTP/1.1 403 Forbidden
# You cannot see this- The
messageof anHttpErroris sent as is, even in production. Write only text the client may see - Other errors do not show their content in production: the response is only
500 Internal Server Error. In development mode, the error page shows the message and the code - Errors from built-in middleware (401 from
basicAuth(), 429 fromrateLimit()and so on) areHttpErrors too, with headers such asWWW-AuthenticateandRetry-After
To change the format of the response, use onError.