【问题标题】:How to return 401 code from post clause in clojure liberator?如何从 clojure liberator 中的 post 子句返回 401 代码?
【发布时间】:2015-05-05 15:55:07
【问题描述】:

我有这样的代码:

(defresource errors []
         :authorized? (fn [ctx] (authorized? ctx))
         :allowed-methods [:post :options]
         :available-media-types media-types
         :post!      (fn [ctx] (-> ctx
                                   parse-json
                                   errors/insert-error)))

授权?函数检查用户令牌,但我还有一些其他规则,我想在帖子中检查!功能。怎么做?我可以从帖子中抛出异常!函数,但我想返回 401 状态码。

【问题讨论】:

    标签: clojure liberator


    【解决方案1】:

    从您的问题中不清楚您要在 :post! 函数中检查什么,但在正常情况下,:post! 函数中的失败不会返回 401 错误。

    如果您想返回 401,那么您可能应该在 :authorized? 函数中检查请求,并从中返回 true 或 false。

    如果您可以详细说明要检查的规则,那么我的答案可能会更具体。

    您可能已经这样做了,但请确保您了解 Liberator decision graph 以及您的请求如何通过它。

    【讨论】:

    • 我决定使用allowed?检查特定用户是否可以发布数据。
    猜你喜欢
    • 2016-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    • 2014-03-02
    相关资源
    最近更新 更多