Albirew/nyaa-pantsu
Albirew
/
nyaa-pantsu
Archivé
1
0
Bifurcation 0

Fix both error message + HTML showing on home page

Also remove util.SendError since it's not very useful.
Cette révision appartient à :
sfan5 2017-06-06 16:22:26 +02:00
Parent f3c8515263
révision 576e11bf42
5 fichiers modifiés avec 16 ajouts et 36 suppressions

Voir le fichier

@ -3,7 +3,6 @@ package router
import (
"encoding/json"
"errors"
"fmt"
"html"
"net/http"
"strconv"
@ -18,7 +17,6 @@ import (
"github.com/NyaaPantsu/nyaa/service/torrent"
"github.com/NyaaPantsu/nyaa/service/upload"
"github.com/NyaaPantsu/nyaa/service/user"
"github.com/NyaaPantsu/nyaa/util"
"github.com/NyaaPantsu/nyaa/util/log"
"github.com/NyaaPantsu/nyaa/util/search"
"github.com/gorilla/mux"
@ -36,7 +34,7 @@ func APIHandler(w http.ResponseWriter, r *http.Request) {
if contentType == "application/json" {
d := json.NewDecoder(r.Body)
if err := d.Decode(&req); err != nil {
util.SendError(w, err, 502)
http.Error(w, err.Error(), http.StatusBadRequest)
}
if req.MaxPerPage == 0 {
@ -75,7 +73,7 @@ func APIHandler(w http.ResponseWriter, r *http.Request) {
torrents, nbTorrents, err := torrentService.GetTorrents(whereParams, req.MaxPerPage, req.MaxPerPage*(req.Page-1))
if err != nil {
util.SendError(w, err, 400)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@ -221,11 +219,10 @@ func APIUploadHandler(w http.ResponseWriter, r *http.Request) {
db.ORM.Create(&file)
}
}
/*if err != nil {
util.SendError(w, err, 500)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}*/
fmt.Printf("%+v\n", torrent)
}
}
// APIUpdateHandler : Controller for updating a torrent with api
@ -299,7 +296,7 @@ func APISearchHandler(w http.ResponseWriter, r *http.Request) {
_, torrents, _, err := search.SearchByQuery(r, pagenum)
if err != nil {
util.SendError(w, err, 400)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

Voir le fichier

@ -9,7 +9,6 @@ import (
"github.com/NyaaPantsu/nyaa/common"
"github.com/NyaaPantsu/nyaa/model"
"github.com/NyaaPantsu/nyaa/service/torrent"
"github.com/NyaaPantsu/nyaa/util"
"github.com/NyaaPantsu/nyaa/util/log"
msg "github.com/NyaaPantsu/nyaa/util/messages"
"github.com/gorilla/mux"
@ -55,12 +54,12 @@ func HomeHandler(w http.ResponseWriter, r *http.Request) {
}
torrents, nbTorrents, err := cache.Impl.Get(search, func() ([]model.Torrent, int, error) {
torrents, nbTorrents, err := torrentService.GetAllTorrents(maxPerPage, maxPerPage*(pagenum-1))
if !log.CheckError(err) {
util.SendError(w, err, 400)
}
return torrents, nbTorrents, err
return torrentService.GetAllTorrents(maxPerPage, maxPerPage*(pagenum-1))
})
if !log.CheckError(err) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
navigationTorrents := navigation{
TotalItem: nbTorrents,

Voir le fichier

@ -9,7 +9,6 @@ import (
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/feeds"
userService "github.com/NyaaPantsu/nyaa/service/user"
"github.com/NyaaPantsu/nyaa/util"
"github.com/NyaaPantsu/nyaa/util/search"
"github.com/gorilla/mux"
)
@ -26,7 +25,7 @@ func RSSHandler(w http.ResponseWriter, r *http.Request) {
if page != "" {
pagenum, err = strconv.Atoi(html.EscapeString(page))
if err != nil {
util.SendError(w, err, 400)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if pagenum <= 0 {
@ -39,13 +38,13 @@ func RSSHandler(w http.ResponseWriter, r *http.Request) {
userIDnum, err := strconv.Atoi(html.EscapeString(userID))
// Should we have a feed for anonymous uploads?
if err != nil || userIDnum == 0 {
util.SendError(w, err, 400)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
_, _, err = userService.RetrieveUserForAdmin(userID)
if err != nil {
util.SendError(w, err, 404)
http.Error(w, "", http.StatusNotFound)
return
}
@ -57,7 +56,7 @@ func RSSHandler(w http.ResponseWriter, r *http.Request) {
_, torrents, err := search.SearchByQueryNoCount(r, pagenum)
if err != nil {
util.SendError(w, err, 400)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
createdAsTime := time.Now()

Voir le fichier

@ -7,7 +7,6 @@ import (
"strconv"
"github.com/NyaaPantsu/nyaa/model"
"github.com/NyaaPantsu/nyaa/util"
"github.com/NyaaPantsu/nyaa/util/log"
msg "github.com/NyaaPantsu/nyaa/util/messages"
"github.com/NyaaPantsu/nyaa/util/search"
@ -40,7 +39,7 @@ func SearchHandler(w http.ResponseWriter, r *http.Request) {
searchParam, torrents, nbTorrents, err := search.SearchByQuery(r, pagenum)
if err != nil {
util.SendError(w, err, 400)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

Voir le fichier

@ -1,14 +0,0 @@
package util
import (
"net/http"
"runtime/debug"
"github.com/NyaaPantsu/nyaa/util/log"
)
// SendError : Send an error as response
func SendError(w http.ResponseWriter, err error, code int) {
log.Warnf("%s:\n%s\n", err, debug.Stack())
http.Error(w, err.Error(), code)
}