feat: exceptions hello world
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user