Experimenting with request state in local errors.
Move the sheet and style declarations after the initial error on the profiles. Use a global URL ID error message for the profiles. Updates #51
This commit is contained in:
parent
a465850adb
commit
e9e527e76a
@ -212,16 +212,32 @@ func PreErrorJSQ(errmsg string, w http.ResponseWriter, r *http.Request, isJs boo
|
|||||||
|
|
||||||
// LocalError is an error shown to the end-user when something goes wrong and it's not the software's fault
|
// LocalError is an error shown to the end-user when something goes wrong and it's not the software's fault
|
||||||
// TODO: Pass header in for this and similar errors instead of having to pass in both user and w? Would also allow for more stateful things, although this could be a problem
|
// TODO: Pass header in for this and similar errors instead of having to pass in both user and w? Would also allow for more stateful things, although this could be a problem
|
||||||
func LocalError(errmsg string, w http.ResponseWriter, r *http.Request, user User) RouteError {
|
/*func LocalError(errmsg string, w http.ResponseWriter, r *http.Request, user User) RouteError {
|
||||||
w.WriteHeader(500)
|
w.WriteHeader(500)
|
||||||
pi := ErrorPage{errorHeader(w, user, phrases.GetErrorPhrase("local_error_title")), errmsg}
|
pi := ErrorPage{errorHeader(w, user, phrases.GetErrorPhrase("local_error_title")), errmsg}
|
||||||
handleErrorTemplate(w, r, pi)
|
handleErrorTemplate(w, r, pi)
|
||||||
return HandledRouteError()
|
return HandledRouteError()
|
||||||
|
}*/
|
||||||
|
|
||||||
|
func LocalError(errmsg string, w http.ResponseWriter, r *http.Request, user User) RouteError {
|
||||||
|
return SimpleError(errmsg, w, r, errorHeader(w, user, ""))
|
||||||
|
}
|
||||||
|
|
||||||
|
func SimpleError(errmsg string, w http.ResponseWriter, r *http.Request, header *Header) RouteError {
|
||||||
|
if header == nil {
|
||||||
|
header = errorHeader(w, GuestUser, phrases.GetErrorPhrase("local_error_title"))
|
||||||
|
} else {
|
||||||
|
header.Title = phrases.GetErrorPhrase("local_error_title")
|
||||||
|
}
|
||||||
|
w.WriteHeader(500)
|
||||||
|
pi := ErrorPage{header, errmsg}
|
||||||
|
handleErrorTemplate(w, r, pi)
|
||||||
|
return HandledRouteError()
|
||||||
}
|
}
|
||||||
|
|
||||||
func LocalErrorJSQ(errmsg string, w http.ResponseWriter, r *http.Request, user User, isJs bool) RouteError {
|
func LocalErrorJSQ(errmsg string, w http.ResponseWriter, r *http.Request, user User, isJs bool) RouteError {
|
||||||
if !isJs {
|
if !isJs {
|
||||||
return LocalError(errmsg, w, r, user)
|
return SimpleError(errmsg, w, r, errorHeader(w, user, ""))
|
||||||
}
|
}
|
||||||
return LocalErrorJS(errmsg, w, r)
|
return LocalErrorJS(errmsg, w, r)
|
||||||
}
|
}
|
||||||
|
@ -28,12 +28,6 @@ func init() {
|
|||||||
|
|
||||||
// TODO: Remove the View part of the name?
|
// TODO: Remove the View part of the name?
|
||||||
func ViewProfile(w http.ResponseWriter, r *http.Request, user c.User, header *c.Header) c.RouteError {
|
func ViewProfile(w http.ResponseWriter, r *http.Request, user c.User, header *c.Header) c.RouteError {
|
||||||
// TODO: Preload this?
|
|
||||||
header.AddSheet(header.Theme.Name + "/profile.css")
|
|
||||||
if user.Loggedin {
|
|
||||||
header.AddScriptAsync("profile_member.js")
|
|
||||||
}
|
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
var replyCreatedAt time.Time
|
var replyCreatedAt time.Time
|
||||||
var replyContent, replyCreatedByName, replyAvatar string
|
var replyContent, replyCreatedByName, replyAvatar string
|
||||||
@ -43,7 +37,13 @@ func ViewProfile(w http.ResponseWriter, r *http.Request, user c.User, header *c.
|
|||||||
// TODO: Do a 301 if it's the wrong username? Do a canonical too?
|
// TODO: Do a 301 if it's the wrong username? Do a canonical too?
|
||||||
_, pid, err := ParseSEOURL(r.URL.Path[len("/user/"):])
|
_, pid, err := ParseSEOURL(r.URL.Path[len("/user/"):])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.LocalError("The provided UserID is not a valid number.", w, r, user)
|
return c.SimpleError(phrases.GetErrorPhrase("url_id_must_be_integer"),w,r,header)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Preload this?
|
||||||
|
header.AddSheet(header.Theme.Name + "/profile.css")
|
||||||
|
if user.Loggedin {
|
||||||
|
header.AddScriptAsync("profile_member.js")
|
||||||
}
|
}
|
||||||
|
|
||||||
var puser *c.User
|
var puser *c.User
|
||||||
|
@ -44,7 +44,7 @@ func ViewTopic(w http.ResponseWriter, r *http.Request, user c.User, header *c.He
|
|||||||
page, _ := strconv.Atoi(r.FormValue("page"))
|
page, _ := strconv.Atoi(r.FormValue("page"))
|
||||||
_, tid, err := ParseSEOURL(urlBit)
|
_, tid, err := ParseSEOURL(urlBit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.PreError(phrases.GetErrorPhrase("url_id_must_be_integer"), w, r)
|
return c.SimpleError(phrases.GetErrorPhrase("url_id_must_be_integer"),w,r,header)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the topic...
|
// Get the topic...
|
||||||
|
Loading…
Reference in New Issue
Block a user