(f handlerFunc)
| 613 | } |
| 614 | |
| 615 | func (h *Handler) OAuth(f handlerFunc) http.HandlerFunc { |
| 616 | return func(w http.ResponseWriter, r *http.Request) { |
| 617 | h.handleOAuthError(w, r, func() error { |
| 618 | // TODO: return correct "success" status |
| 619 | status := 200 |
| 620 | start := time.Now() |
| 621 | |
| 622 | defer func() { |
| 623 | if e := recover(); e != nil { |
| 624 | log.Error("%s:\n%s", e, debug.Stack()) |
| 625 | impart.WriteError(w, impart.HTTPError{http.StatusInternalServerError, "Something didn't work quite right."}) |
| 626 | status = 500 |
| 627 | } |
| 628 | |
| 629 | log.Info(h.app.ReqLog(r, status, time.Since(start))) |
| 630 | }() |
| 631 | |
| 632 | err := f(h.app.App(), w, r) |
| 633 | if err != nil { |
| 634 | if err, ok := err.(impart.HTTPError); ok { |
| 635 | status = err.Status |
| 636 | } else { |
| 637 | status = 500 |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | return err |
| 642 | }()) |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | func (h *Handler) AllReader(f handlerFunc) http.HandlerFunc { |
| 647 | return func(w http.ResponseWriter, r *http.Request) { |
no test coverage detected