MCPcopy Index your code
hub / github.com/writefreely/writefreely / PlainTextAPI

Method PlainTextAPI

handle.go:583–613  ·  view source on GitHub ↗
(f handlerFunc)

Source from the content-addressed store, hash-verified

581}
582
583func (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
615func (h *Handler) OAuth(f handlerFunc) http.HandlerFunc {
616 return func(w http.ResponseWriter, r *http.Request) {

Callers 1

InitRoutesFunction · 0.80

Calls 3

handleTextErrorMethod · 0.95
AppMethod · 0.65
fFunction · 0.50

Tested by

no test coverage detected