Set status code when rendering component #1055
-
Hi all, how would I return a specific status code when rendering a templ component? The following code works but I'm getting an error about the header being redundant:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
You must have already written a status code to the writer, or have already written to the body somewhere else in the code. If you write something to the body before you call WriteHeader, it will default to 200. I would check all the validation errors at the top of the handler, write the appropriate status code, then write the body contents. |
Beta Was this translation helpful? Give feedback.
re: validation, I cover it using HTMX and templ in the talk I did at Big Sky Dev Con, see https://templ.guide/media/
It uses the approach of creatinf a model that has validation on it: