more helpful error messages.

This commit is contained in:
fiatjaf
2023-11-23 21:04:21 -03:00
parent 991a3952c3
commit 8fb8acb86f

View File

@@ -449,7 +449,7 @@ type ErrorPage struct {
HeadCommonPartial `tmpl:"head_common"` HeadCommonPartial `tmpl:"head_common"`
TopPartial `tmpl:"top"` TopPartial `tmpl:"top"`
FooterPartial `tmpl:"footer"` FooterPartial `tmpl:"footer"`
Message string Message template.HTML
Errors string Errors string
} }
@@ -457,15 +457,15 @@ func (e *ErrorPage) TemplateText() string {
if e.Message != "" { if e.Message != "" {
return tmplError 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" switch {
if strings.Contains(e.Errors, "invalid checksum") { case 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" e.Message = "It looks like you entered an invalid event code.<br> Check if you copied it fully, a good idea is compare the first and the last characters."
} else if strings.Contains(e.Errors, "couldn't find this") { case strings.Contains(e.Errors, "couldn't find this"):
e.Message = "I can't find the event, maybe it is new and has not been already propagated on the relays I'm checking; you can try again in some time" e.Message = "Can't find the event in the relays. Try getting an `nevent1` code with relay hints."
} else if strings.Contains(e.Errors, "invalid bech32 string length") { case strings.Contains(e.Errors, "invalid bech32 string length"), strings.Contains(e.Errors, "invalid separator"):
e.Message = "I can't find what you are serching for, and this doesn't seem an event at all, sorry" e.Message = "You have typed a wrong event code, we need a URL path that starts with /npub1, /nprofile1, /nevent1, /naddr1, or something like /name@domain.com (or maybe just /domain.com) or an event id as hex (like /aef8b32af...)"
} else if strings.Contains(e.Errors, "invalid separator") { default:
e.Message = "This is so wrong I can't even begin to help you, you are probably trolling me" e.Message = "I can't give any suggestions to solve the problem.<br> Please tag <a href='/dtonon.com'>daniele</a> and <a href='/fiatjaf.com'>fiatjaf</a> and complain!"
} }
return tmplError return tmplError
} }