This commit is contained in:
lbenedar
2026-03-05 17:46:26 +03:00
parent c2883b9916
commit b50cd42f4f
8 changed files with 70 additions and 30 deletions

View File

@@ -1,9 +1,12 @@
package main
import (
"errors"
"fmt"
"net/http"
"runtime/debug"
"github.com/go-playground/form/v4"
)
func (app *application) serverError(w http.ResponseWriter, err error) {
@@ -20,3 +23,20 @@ func (app *application) clientError(w http.ResponseWriter, status int) {
func (app *application) notFound(w http.ResponseWriter) {
app.clientError(w, http.StatusNotFound)
}
func (app *application) decodePostForm(r *http.Request, snippetForm *snippetCreateForm) error {
err := r.ParseForm()
if err != nil {
return err
}
err = app.formDecoder.Decode(&snippetForm, r.PostForm)
if err != nil {
var invalidDecoderError *form.InvalidDecoderError
if errors.As(err, &invalidDecoderError) {
panic("Invalid decoder error")
}
return err
}
return nil
}