Lasa is a stateless proxy that generates a RSS or an Atom feed from a Standard.site publication. lasa.anhgelus.world
rss atom atprotocol standard-site atproto
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(cli): better handle of errors

+31 -5
+22
cmd/lasad/errors.go
··· 1 + package main 2 + 3 + import ( 4 + "errors" 5 + "net/http" 6 + 7 + "tangled.org/anhgelus.world/xrpc/atproto" 8 + ) 9 + 10 + func HandleErrors(w http.ResponseWriter, err error) { 11 + w.Header().Add("Content-Type", "text/plain") 12 + if atproto.IsErrCannotParse(err) { 13 + w.WriteHeader(http.StatusBadRequest) 14 + w.Write([]byte(err.Error())) 15 + return 16 + } else if errors.Is(err, atproto.ErrHandleNotFound) || errors.Is(err, atproto.ErrDIDNotFound{}) { 17 + w.WriteHeader(http.StatusNotFound) 18 + w.Write([]byte(err.Error())) 19 + return 20 + } 21 + panic(err) 22 + }
+9 -5
cmd/lasad/run.go
··· 78 78 dir := r.Context().Value(keyDir).(*Directory) 79 79 err := dir.Feed(r.Context(), w, r, "rss", lasa.GenerateRSS) 80 80 if err != nil { 81 - panic(err) 81 + HandleErrors(w, err) 82 + return 82 83 } 83 84 }) 84 85 mux.HandleFunc("GET /{id}/{rkey}/atom", func(w http.ResponseWriter, r *http.Request) { 85 86 dir := r.Context().Value(keyDir).(*Directory) 86 87 err := dir.Feed(r.Context(), w, r, "atom", lasa.GenerateAtom) 87 88 if err != nil { 88 - panic(err) 89 + HandleErrors(w, err) 90 + return 89 91 } 90 92 }) 91 93 mux.HandleFunc("GET /{id}/{$}", func(w http.ResponseWriter, r *http.Request) { ··· 93 95 client := ctx.Value(keyClient).(xrpc.Client) 94 96 did, err := lasa.Resolve(ctx, client.Directory(), r.PathValue("id")) 95 97 if err != nil { 96 - w.WriteHeader(http.StatusBadRequest) 98 + HandleErrors(w, err) 97 99 return 98 100 } 99 101 dir := ctx.Value(keyDir).(*Directory) 100 102 b, err := dir.Author(ctx, did) 101 103 if err != nil { 102 - panic(err) 104 + HandleErrors(w, err) 105 + return 103 106 } 104 107 w.Write(b) 105 108 }) 106 109 mux.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) { 107 110 b, err := files.ReadFile("index.html") 108 111 if err != nil { 109 - panic(err) 112 + HandleErrors(w, err) 113 + return 110 114 } 111 115 w.Write(b) 112 116 })