小编Cur*_*son的帖子

在通知中显示 API 错误

我在文档中缺少一些基本的东西。当我收到 API 验证错误时,我会返回一个状态代码和消息。看起来 React-Admin 正在将状态代码转换为通用的 HTTP 错误代码。

我的错误响应。

{"error":
    {"statusCode":422,
    "name":"Error",
    "message":"User with same first and last name already on team."}
}
Run Code Online (Sandbox Code Playgroud)

当我的 API 响应该响应时,我在通知框中看到“不可处理的实体”。我正在使用 SimpleForm。

我知道状态代码正在被识别,因为我已经更改了 422 并且它显示了相应的 HTTP 错误描述。

在文档中它说在你的数据提供者中抛出和错误。我已经将 Simple Rest 数据提供程序移到我的项目中,并尝试在各个地方抛出错误,但客户端没有任何变化。

https://marmelab.com/react-admin/DataProviders.html#error-format

如果您从您的 API 中自定义了错误,我很感激您提供的任何提示。谢谢。

react-admin

7
推荐指数
1
解决办法
3538
查看次数

如何在没有控制器的情况下保护rspec_api_documentation apitome路由

我有一组API文档页面,我想使用设计密码保护.使用rspec_api_documentation生成文档.gem使用rspec来执行API方法并创建html或json doc文件.我正在生成json并使用另一个gem,apitome作为查看器.

这一切都很漂亮,我的api文档可以在/ api/docs找到,但我无法弄清楚如何要求身份验证来查看文档.

通过apitome查看文档,因此它使用rails.routes.rb中没有路由,但apitom初始化程序会安装文档.

从apitom初始化器:

# This determines where the Apitome routes will be mounted. Changing this to "/api/documentation" for instance would
# allow you to browse to http://localhost:3000/api/documentation to see your api documentation. Set to nil and mount
# it yourself if you need to.
config.mount_at = "/api/docs"
Run Code Online (Sandbox Code Playgroud)

https://github.com/zipmark/rspec_api_documentation

https://github.com/modeset/apitome

我发现这个How-to应该会使网站上的每个页面都需要进行身份验证,但我仍然可以在不登录的情况下点击文档URL.

#https://github.com/plataformatec/devise/wiki/How-To:-Require-authentication-for-all-pages
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助.

rspec ruby-on-rails devise

2
推荐指数
1
解决办法
1176
查看次数

标签 统计

devise ×1

react-admin ×1

rspec ×1

ruby-on-rails ×1