I would like to style Errors in my Go Web Application.
Currently I am handling errors like the following example:
if !ok {
http.Error(w, "Username and/or password do not match", http.StatusForbidden)
return
}
However this causes the error message to be displayed in the browser as simple text. I would like to style my errors with HTML & CSS, but it seems bad practice to simply ignore the http.Error
method and use:
TPL := template.Must(template.ParseGlob("templates/*.gohtml"))
if !ok {
TPL.ExecuteTemplate(w, "usernamePasswordMismatch.gohtml", nil)
}
Can someone recommend a way to properly handle my error, with the http.Error
method or something similar, and still style my Error page with HTML & CSS?