diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go b/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go index 03e693c75..fe9ce293b 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go @@ -175,11 +175,11 @@ func Setup( ).Methods("GET", "POST", "OPTIONS") r0mux.Handle("/auth/{authType}/fallback/web?session={sessionID}", - common.MakeHtmlAPI("authfallback", func(w http.ResponseWriter, req *http.Request) util.JSONResponse { + common.MakeHTMLAPI("authfallback", func(w http.ResponseWriter, req *http.Request) util.JSONResponse { vars := mux.Vars(req) return AuthFallback(w, req, vars["authType"], vars["sessionID"], cfg) }), - ).Methods("GET", "OPTIONS") + ).Methods("GET", "POST", "OPTIONS") r0mux.Handle("/pushrules/", common.MakeExternalAPI("push_rules", func(req *http.Request) util.JSONResponse { diff --git a/src/github.com/matrix-org/dendrite/common/httpapi.go b/src/github.com/matrix-org/dendrite/common/httpapi.go index 076845bbe..fae17c736 100644 --- a/src/github.com/matrix-org/dendrite/common/httpapi.go +++ b/src/github.com/matrix-org/dendrite/common/httpapi.go @@ -41,12 +41,17 @@ func MakeExternalAPI(metricsName string, f func(*http.Request) util.JSONResponse // MakeHTMLAPI adds Span metrics to the HTML Handler function // This is used to serve HTML template -func MakeHtmlAPI(metricsName string, f func(w http.ResponseWriter, *http.Request)) http.Handler { +func MakeHTMLAPI(metricsName string, f func(http.ResponseWriter, *http.Request) util.JSONResponse) http.Handler { withSpan := func(w http.ResponseWriter, req *http.Request) { span := opentracing.StartSpan(metricsName) defer span.Finish() req = req.WithContext(opentracing.ContextWithSpan(req.Context(), span)) - f(w, req) + if err := f(w, req); err { + h := util.MakeJSONAPI(util.NewJSONRequestHandler(func(req *http.Request) util.JSONResponse { + return err + })) + h.ServeHTTP(w, req) + } } return prometheus.InstrumentHandler(metricsName, http.HandlerFunc(withSpan))