ch17
This commit is contained in:
@@ -13,7 +13,13 @@ func (app *application) serverError(w http.ResponseWriter, err error) {
|
||||
trace := fmt.Sprintf("%s\n%s", err.Error(), debug.Stack())
|
||||
app.errorLog.Output(2, trace)
|
||||
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
var errorText string
|
||||
if app.debug {
|
||||
errorText = trace
|
||||
} else {
|
||||
errorText = http.StatusText(http.StatusInternalServerError)
|
||||
}
|
||||
http.Error(w, errorText, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
func (app *application) clientError(w http.ResponseWriter, status int) {
|
||||
@@ -24,13 +30,13 @@ func (app *application) notFound(w http.ResponseWriter) {
|
||||
app.clientError(w, http.StatusNotFound)
|
||||
}
|
||||
|
||||
func (app *application) decodePostForm(r *http.Request, snippetForm any) error {
|
||||
func (app *application) decodePostForm(r *http.Request, templateForm any) error {
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = app.formDecoder.Decode(&snippetForm, r.PostForm)
|
||||
err = app.formDecoder.Decode(&templateForm, r.PostForm)
|
||||
if err != nil {
|
||||
var invalidDecoderError *form.InvalidDecoderError
|
||||
if errors.As(err, &invalidDecoderError) {
|
||||
|
||||
Reference in New Issue
Block a user