Fork me on GitHub
#biff
<
2023-08-30
>
Martynas Maciulevičius08:08:50

How does one make error 500 look the same as the other parts of the webpage? Should I assoc the on-error into each request when it happens? Previously there was a parameter where I could provide the on-error handler for wrap-internal-error but now that code is marked as deprecated. I'd like to know if there is a different place where I could provide on-error so that it would be picked up by both places. If I provide on-error like this then it's picked up for 40x errors but not 50x:

(def handler (-> (biff/reitit-handler {:routes routes
                                       :on-error #'ui/error-page-handler})
                 biff/wrap-base-defaults))
And this:
(defn error-page-handler [{:keys [status]}]
  {:status status
   :headers {"content-type" "text/html"}
   :body (->> (page {} [:h1 {} (biff-util/http-status->msg status)])
              rum/render-static-markup)})
I think I'd like to be able to specify biff.middleware/on-error but I don't know where to do it.

Jacob O'Bryant16:08:39

You can set it on the system map, since the system map gets merged into incoming ring requests by the use-jetty component:

(def initial-system
  {:biff.middleware/on-error #'ui/error-page-handler
   :biff/plugins #'plugins
   ...})

🙌 2
Jacob O'Bryant16:08:22

Reading through the code again, it looks like you'll need to set it in both places--on the system map for 50x errors and in biff/reitit-handler for 40x errors. I should probably modify the default template so that it starts out with a custom on-error function in ui.clj, since that probably should be overridden by most projects. I'll make a note of that.

🙌 2
Jacob O'Bryant16:08:00

and maybe see if there's a way to have biff/reitit-handler reuse the :biff.middleware/on-error value from the system map...

🙌 2
ianjones16:08:54

built this calendar component with biff and it turned out really nice https://twitter.com/_jonesian/status/1696745494440272216?s=20

📆 4
🔥 6
wow 2
Jacob O'Bryant17:08:53

That's awesome 🙂 I'll add that link to the (not explicitly existing yet) "things built with biff" section in the docs

vonadz20:08:36

Is there something special that needs to be done for tailwind classes that uses /? Like w-1/4 ? I'm getting "Invalid token" errors thrown when trying to use classes with a slash in them.

ianjones20:08:37

you could opt for quoting a vector for those… :class '[w-1/4]

marcofiset20:08:48

Are you trying to specify this class like so: [:div.w-1/4 ...] ? That's not possible using clojure keywords. I usually do the following instead:

[:div.any.other.classes.without-slashes {:class "w-1/4"} ...]

vonadz20:08:28

thanks for the quick advice 🙂 yeah I ended up figuring out the second solution!

Jacob O'Bryant21:08:15

You can also mix them--I usually do symbols, but there are some tailwind classes that aren't valid clojure symbols:

[:div {:class '[px-4
                "mt-[55px]"]}
 ...]

👍 2
marcofiset20:08:26

Is there a way to get the XTDB node in the REPL? I'd like to run some ad hoc queries without having to initiate an HTTP request. From the docs, it seems like I could get it from the system map, but I always get nil when trying to deref the biff/system atom.

ianjones20:08:24

do you have a repl namespace?

ianjones20:08:45

theres a

(defn get-context
  []
  (biff/assoc-db @main/system))
method that you can call to get access

sergey.shvets20:08:47

(defn get-context []
  (biff/assoc-db @main/system))
from the repl namespace

ianjones20:08:06

ie:

(let [{:keys [biff/db]} (get-context)]
    (biff/q db '{:find  (pull w [*])
                 :where [[w :workout/created-at]]}))

ianjones20:08:31

essentially the same thing that gets passed to a route handler i think

marcofiset20:08:24

:man-facepalming: I was trying to deref biff/system instead of my.namespace/system It's all good now. 😅 Thanks!

marcofiset20:08:40

I see the repl namespace now. Don't know how I missed it

sergey.shvets20:08:46

Had the same issue. @U7YNGKDHA probably worth mentioning in some paragraph in getting started?

Jacob O'Bryant21:08:19

it is 🙂 though it is quite possible I should make that more prominent somehow; I'll think about that.

sergey.shvets21:08:11

Probably, an example on how to query db without http request/with repl? Everyone will have this need pretty quickly and many will try this before they'll update anything in htmx)

Jacob O'Bryant21:08:30

You mean like the example in repl.clj ? I could turn the "Jacking in" section into a "REPL-driven development" section and then paste in the example from repl.clj .

sergey.shvets21:08:27

I think that should be enough. Nobody will miss REPL-driven development section when they look for repl.

👌 4
Martynas Maciulevičius15:09:12

I click a button and def stuff that I want to use in the namespace. Then I can simply use DB and even my IDs that I had submitted into the handler.

(defn handler [ctx]
  (def my-stuff (:my-stuff ctx))
  (def my-more-stuff (:my-stuff1 ctx))
  200)

2