Fork me on GitHub
#yada
<
2017-03-01
>
sickill10:03:20

[true (yada/as-resource nil)] gives me 404 status with default error page, [true (yada/as-resource (io/resource "asciinema/errors/404.html"))] gives me my custom error page but the status is 200

sickill10:03:20

to get status 404 with custom page should I use sth like [true (yada/resource {:properties {:exists? false} :responses {404 {:response (fn [] ...)}}})]?

sickill10:03:01

I guess I can also wrap the whole thing in a middleware

malcolmsparks10:03:34

Not really. Ring middleware is synchronous

malcolmsparks10:03:05

But you write something that wraps in a chain

malcolmsparks10:03:29

But that's really what interceptors are doing

sickill10:03:46

hmm, but I wouldn't be modifying the existing response (which could be manifold deferred in other cases indeed) , as in this case the whole response is nil

sickill10:03:02

I know that ring middleware is not really compatible with yada in most cases (when it modifies the response), but in this case should be fine imo

malcolmsparks10:03:21

Except for error scenarios

sickill10:03:57

hmm, could you elaborate?

sickill10:03:10

if there's no match for a bidi tree then aleph gets nil as a response

malcolmsparks10:03:16

if you're happy that there's no change of any deferreds coming out of your yada interceptor chain, then it is safe

malcolmsparks10:03:53

so you're trying to do

[true (yada/as-resource nil)]
but with a custom 404?

malcolmsparks10:03:51

in which case, you can return a custom 404 page in your response function

sickill10:03:54

so the middleware wrapping option would be when I don't have [true ...] in my bidi tree at all

malcolmsparks10:03:25

(fn [ctx] (assoc (:response ctx) :status 404 :body "..."})

malcolmsparks10:03:36

that will override the status to 404

malcolmsparks10:03:52

you can write that resource once and use as a backstop in your bidi tree

sickill10:03:13

I'm doing similary, yeah (I created my wrapper for yada/resource), but what I'm trying to solve now is the 404 on the routes level

sickill10:03:18

so either [true (yada/resource {:produces "text/html" :response (fn [ctx] (assoc (:response ctx) :status 404 :body "..."})})] or wrapping bidi tree (coerced to handler) with a middleware which checks whether response is nil and then returns custom 404 error response

malcolmsparks10:03:35

sounds fine to me

sickill10:03:48

btw, if I want to report exceptions to external service (Bugsnag) I can safely do that from :logger fn, right?

malcolmsparks10:03:54

I think others are doing something similar