From 97b814ab3371bc3bd47548ac474336d809e53d79 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 13 Nov 2021 22:44:52 +0100 Subject: [PATCH] outpost/proxy: show better error when hostname isn't configured Signed-off-by: Jens Langhammer --- internal/outpost/proxyv2/handlers.go | 20 +++++++++++++++++++- web/src/pages/outposts/OutpostForm.ts | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/internal/outpost/proxyv2/handlers.go b/internal/outpost/proxyv2/handlers.go index c7382844d..f54170f5b 100644 --- a/internal/outpost/proxyv2/handlers.go +++ b/internal/outpost/proxyv2/handlers.go @@ -1,6 +1,8 @@ package proxyv2 import ( + "encoding/json" + "fmt" "net/http" "strings" "time" @@ -60,7 +62,23 @@ func (ps *ProxyServer) Handle(rw http.ResponseWriter, r *http.Request) { } ps.log.WithField("host", host).Warning("no app for hostname") - rw.WriteHeader(400) + + rw.Header().Set("Content-Type", "application/json") + rw.WriteHeader(http.StatusBadRequest) + j := json.NewEncoder(rw) + j.SetIndent("", "\t") + err := j.Encode(struct { + Message string + Host string + Detail string + }{ + Message: "no app for hostname", + Host: host, + Detail: fmt.Sprintf("Check the outpost settings and make sure '%s' is included.", host), + }) + if err != nil { + ps.log.WithError(err).Warning("Failed to write error body") + } return } ps.log.WithField("host", host).Trace("passing to application mux") diff --git a/web/src/pages/outposts/OutpostForm.ts b/web/src/pages/outposts/OutpostForm.ts index f5f5f8b80..b08c57bc5 100644 --- a/web/src/pages/outposts/OutpostForm.ts +++ b/web/src/pages/outposts/OutpostForm.ts @@ -73,7 +73,7 @@ export class OutpostForm extends ModelForm { value=${ifDefined(provider.pk)} ?selected=${selected} > - ${provider.assignedApplicationName} (${provider.name}) + ${provider.assignedApplicationName} (${provider.externalHost}) `; }); });