(web bool, f userHandlerFunc, a authFunc)
| 314 | } |
| 315 | |
| 316 | func (h *Handler) UserAll(web bool, f userHandlerFunc, a authFunc) http.HandlerFunc { |
| 317 | return func(w http.ResponseWriter, r *http.Request) { |
| 318 | handleFunc := func() error { |
| 319 | var status int |
| 320 | start := time.Now() |
| 321 | |
| 322 | defer func() { |
| 323 | if e := recover(); e != nil { |
| 324 | log.Error("%s: %s", e, debug.Stack()) |
| 325 | impart.WriteError(w, impart.HTTPError{http.StatusInternalServerError, "Something didn't work quite right."}) |
| 326 | status = 500 |
| 327 | } |
| 328 | |
| 329 | log.Info(h.app.ReqLog(r, status, time.Since(start))) |
| 330 | }() |
| 331 | |
| 332 | u, err := a(h.app.App(), r) |
| 333 | if err != nil { |
| 334 | if err, ok := err.(impart.HTTPError); ok { |
| 335 | status = err.Status |
| 336 | } else { |
| 337 | status = 500 |
| 338 | } |
| 339 | return err |
| 340 | } |
| 341 | |
| 342 | err = f(h.app.App(), u, w, r) |
| 343 | if err == nil { |
| 344 | status = 200 |
| 345 | } else if err, ok := err.(impart.HTTPError); ok { |
| 346 | status = err.Status |
| 347 | } else { |
| 348 | status = 500 |
| 349 | } |
| 350 | |
| 351 | return err |
| 352 | } |
| 353 | |
| 354 | if web { |
| 355 | h.handleHTTPError(w, r, handleFunc()) |
| 356 | } else { |
| 357 | h.handleError(w, r, handleFunc()) |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | func (h *Handler) RedirectOnErr(f handlerFunc, loc string) handlerFunc { |
| 363 | return func(app *App, w http.ResponseWriter, r *http.Request) error { |
no test coverage detected