From 9f6726023c1102ca3f3f16bf33fddc3401193119 Mon Sep 17 00:00:00 2001 From: Daniele Tonon Date: Thu, 16 Nov 2023 15:04:44 +0100 Subject: [PATCH] Manage not existen or inactive relay --- pages.go | 3 +++ render_relay.go | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pages.go b/pages.go index 8c6018e..73ab603 100644 --- a/pages.go +++ b/pages.go @@ -424,6 +424,9 @@ type ErrorPage struct { } func (e *ErrorPage) TemplateText() string { + if e.Message != "" { + return tmplError + } e.Message = "I cannot give any suggestions to solve the problem, maybe the best solution is to pubblicy blame the devs on Nostr" if strings.Contains(e.Errors, "invalid checksum") { e.Message = "It seems you entered an invalid event code, try to check if it is correct; a good idea is compare the first and the last characters" diff --git a/render_relay.go b/render_relay.go index cf574ba..1dbe010 100644 --- a/render_relay.go +++ b/render_relay.go @@ -25,7 +25,18 @@ func renderRelayPage(w http.ResponseWriter, r *http.Request) { } // relay metadata - info, _ := nip11.Fetch(r.Context(), hostname) + info, err := nip11.Fetch(r.Context(), hostname) + if err != nil { + w.Header().Set("Cache-Control", "max-age=60") + errorPage := &ErrorPage{ + Message: "The relay you are looking for does not exist or is offline; check the name in the url or try later", + Errors: err.Error(), + } + errorPage.TemplateText() + w.WriteHeader(http.StatusNotFound) + ErrorTemplate.Render(w, errorPage) + return + } if info == nil { info = &nip11.RelayInformationDocument{ Name: hostname,