我正在使用 liberator 作为 REST 服务,我的内容类型是 json。
当:authorized?
(或其他决策)失败时,它会返回我不想要的text/html
。
我需要解放器为所有类型的错误返回 json 数据格式。
处理程序
可用于自定义在不同情况下要执行的操作,例如句柄确定、找不到资源或用户未进行身份验证。例如:
(resource
:available-media-types ["application/json"]
:authorized? (fn [ctx] ...)
:handle-unauthorized {:message "You need to be authenticated"}
:exists? (fn [ctx] ...)
:handle-not-found {:message "Resource not found"})
与其他情况一样,处理程序可以是常量值或将生成它的函数。