(f handlerFunc)
| 581 | } |
| 582 | |
| 583 | func (h *Handler) PlainTextAPI(f handlerFunc) http.HandlerFunc { |
| 584 | return func(w http.ResponseWriter, r *http.Request) { |
| 585 | h.handleTextError(w, r, func() error { |
| 586 | // TODO: return correct "success" status |
| 587 | status := 200 |
| 588 | start := time.Now() |
| 589 | |
| 590 | defer func() { |
| 591 | if e := recover(); e != nil { |
| 592 | log.Error("%s:\n%s", e, debug.Stack()) |
| 593 | status = http.StatusInternalServerError |
| 594 | w.WriteHeader(status) |
| 595 | fmt.Fprintf(w, "Something didn't work quite right. The robots have alerted the humans.") |
| 596 | } |
| 597 | |
| 598 | log.Info(fmt.Sprintf("\"%s %s\" %d %s \"%s\" \"%s\"", r.Method, r.RequestURI, status, time.Since(start), r.UserAgent(), r.Host)) |
| 599 | }() |
| 600 | |
| 601 | err := f(h.app.App(), w, r) |
| 602 | if err != nil { |
| 603 | if err, ok := err.(impart.HTTPError); ok { |
| 604 | status = err.Status |
| 605 | } else { |
| 606 | status = http.StatusInternalServerError |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | return err |
| 611 | }()) |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | func (h *Handler) OAuth(f handlerFunc) http.HandlerFunc { |
| 616 | return func(w http.ResponseWriter, r *http.Request) { |
no test coverage detected