all repos — homestead @ c7165476f375b097761e729ac14f9b8a68af98c6

Code for my website

simplify HTTP error module

Alan Pearce
commit

c7165476f375b097761e729ac14f9b8a68af98c6

parent

8267148e988f22647aa735652dafd06c692b047f

1 file changed, 7 insertions(+), 2 deletions(-)

changed files
M domain/content/publisher/mux.godomain/content/publisher/mux.go
@@ -12,12 +12,17 @@ )
type user struct{} +var ( + ErrCannotDetermineUser = ihttp.NewError("cannot determine user", http.StatusInternalServerError) + ErrRenderFailure = ihttp.NewError("failed to render page", http.StatusInternalServerError) +) + func (app *App) WithUserContext(fn ihttp.HandleFunc) ihttp.HandleFunc { return func(w http.ResponseWriter, r *http.Request) ihttp.Error { ctx := r.Context() who, err := app.localClient.WhoIs(ctx, r.RemoteAddr) if err != nil { - return ihttp.InternalServerError("cannot determine user", err) + return ErrCannotDetermineUser } return fn(w, r.WithContext(
@@ -35,7 +40,7 @@ },
User: user.LoginName, }).Render(w) if err != nil { - return ihttp.InternalServerError("Failed to render index page", err) + return ErrRenderFailure } return nil