feat: exceptions hello world

This commit is contained in:
Guz
2025-03-05 10:43:42 -03:00
parent d2308b5a1b
commit 489a696e82

View File

@@ -1,10 +1,12 @@
package router
import (
"errors"
"log/slog"
"net/http"
"forge.capytal.company/loreddev/x/smalltrip"
"forge.capytal.company/loreddev/x/smalltrip/exceptions"
"forge.capytal.company/loreddev/x/smalltrip/middleware"
"forge.capytal.company/loreddev/x/tinyssert"
)
@@ -19,11 +21,17 @@ func New(assertions tinyssert.Assertions, log *slog.Logger, dev bool) http.Handl
} else {
r.Use(middleware.PersistentCache())
}
r.Use(exceptions.Middleware())
r.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("Hello world"))
})
r.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {
exceptions.InternalServerError(errors.New("TEST ERROR"),
exceptions.WithData("test-data", "test-value"),
).ServeHTTP(w, r)
})
return r
}