if err != nil { if rerr, ok := err.(*web.RequestError); ok && rerr.Code == http.StatusNotFound { http.NotFound(w, r) return } http.Error(w, err.Error(), http.StatusInternalServerError) return }
func getArticle(w http.ResponseWriter, r *http.Request) { articleId := r.URL.Query().Get("id") if articleId == "" { web.NewRequestError(http.StatusBadRequest, "Missing article ID") return } // ... }In this example, we create a Request Error if the article ID is missing from the request URL. We set the status code to 400 Bad Request and the error message to "Missing article ID". Package Library: The package library used in these examples is github.com.garyburd.twister.web.