Fork me on GitHub
#reitit
<
2019-12-11
>
mgrbyte15:12:06

n00bie question - Is there an idiom for handling/using ring.util.http-response with the default exception middleware? I have an existing handler that returns not-authorized! but it gets wrapped:

Fail in create-person
Security - only admins can create a person.

expected: (ru-hp/unauthorized? response)

  actual: (not	  
	   (ru-hp/unauthorized?
	    {:status 400,
	     :body
	     {:type "response",
	      :response
	      {:status 401,
	       :headers {},
	       :body
	       {:text "Missing required role",
	        :required #{:person.role/admin},
	        :roles nil}},
	      :message "HTTP 401"},
	     :headers nil}))

mgrbyte15:12:44

nm, read the source and figured out that I need to override the default :ring/response handler.

👍 4
mgrbyte10:12:38

The solution I came up with was to replace exception/exception-middleware with:

(exception/create-exception-middleware
    (merge exception/default-handlers
                 {:ring-util.http-response/response (:reitit.ring/response exception/default-handlers)}))

ikitommi16:12:02

@U08715BSS could be enabled by default. PR welcome!

mgrbyte16:12:14

I will try and find time do so soon :thumbsup:

mgrbyte16:12:49

also have a few suggestions/comments regarding the exception middleware - seems to be multiple ways to do it, seems to me that coerce-exceptions-middleware and exception-middleware are kinda mutually exclusive? 🙂

ikitommi16:12:54

yes, the latter coerce-... was first, could be removed in 1.0.0

👍 4