Fix filesystem error handler
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package webcontroller
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"fornaxian.tech/log"
|
||||
"fornaxian.tech/pixeldrain_api_client/pixelapi"
|
||||
"fornaxian.tech/util"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
@@ -25,16 +27,19 @@ func (wc *WebController) serveDirectory(w http.ResponseWriter, r *http.Request,
|
||||
|
||||
node, err := td.PixelAPI.GetFilesystemPath(path)
|
||||
if err != nil {
|
||||
if err.Error() == "not_found" || err.Error() == "path_not_found" {
|
||||
wc.serveNotFound(w, r)
|
||||
} else if err.Error() == "forbidden" {
|
||||
wc.serveForbidden(w, r)
|
||||
} else if err.Error() == "authentication_required" {
|
||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||
} else if err.Error() == "unavailable_for_legal_reasons" {
|
||||
wc.serveUnavailableForLegalReasons(w, r)
|
||||
} else if err.Error() == "permission_denied" {
|
||||
wc.serveForbidden(w, r)
|
||||
if apiErr, ok := errors.AsType[pixelapi.Error](err); ok {
|
||||
switch apiErr.StatusCode {
|
||||
case "not_found", "path_not_found":
|
||||
wc.serveNotFound(w, r)
|
||||
case "forbidden":
|
||||
wc.serveForbidden(w, r)
|
||||
case "authentication_required":
|
||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||
case "unavailable_for_legal_reasons":
|
||||
wc.serveUnavailableForLegalReasons(w, r)
|
||||
case "permission_denied":
|
||||
wc.serveForbidden(w, r)
|
||||
}
|
||||
} else {
|
||||
log.Error("Failed to get path: %s", err)
|
||||
wc.templates.Run(w, r, "500", td)
|
||||
|
||||
Reference in New Issue
Block a user