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 record not found and avoid panicing on exit signal

+14 -2
+4
cmd/lasad/errors.go
··· 4 4 "errors" 5 5 "net/http" 6 6 7 + "tangled.org/anhgelus.world/xrpc" 7 8 "tangled.org/anhgelus.world/xrpc/atproto" 8 9 ) 9 10 ··· 17 18 errorNotFound(w, err) 18 19 return 19 20 } else if e, ok := errors.AsType[atproto.ErrDIDNotFound](err); ok { 21 + errorNotFound(w, e) 22 + return 23 + } else if e, ok := errors.AsType[xrpc.ErrStandardResponse](err); ok && errors.Is(err, xrpc.ErrRecordNotFound) { 20 24 errorNotFound(w, e) 21 25 return 22 26 }
+10 -2
cmd/lasad/run.go
··· 3 3 import ( 4 4 "context" 5 5 "embed" 6 + "errors" 6 7 "fmt" 7 8 "log/slog" 8 9 "net" ··· 125 126 }() 126 127 select { 127 128 case <-ctx.Done(): 128 - err = context.Cause(ctx) 129 + slog.Warn("received stop signal") 129 130 case err = <-ch: 130 131 } 131 132 slog.Info("exiting") ··· 144 145 w.code = statusCode 145 146 } 146 147 147 - func middlewares(h http.Handler, ctx context.Context) http.Handler { 148 + func middlewares(h http.Handler, parent context.Context) http.Handler { 148 149 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 149 150 if strings.HasPrefix(r.RequestURI, "/favicon.ico") { 150 151 w.WriteHeader(http.StatusNotFound) 151 152 return 152 153 } 154 + 155 + ctx, cancel := context.WithCancelCause(parent) 156 + defer cancel(errors.New("handling finished")) 157 + 153 158 limiter := ctx.Value(keyLimiter).(*Limiter) 154 159 status := &statusWriter{w, http.StatusOK} 155 160 log := slog.With("uri", r.RequestURI) ··· 164 169 if err := recover(); err != nil { 165 170 w.WriteHeader(http.StatusInternalServerError) 166 171 log.Error("panic!", "error", err, "duration", time.Since(now)) 172 + if e, ok := err.(error); ok { 173 + cancel(e) 174 + } 167 175 } 168 176 }() 169 177