[英]How can I make my Rails app return a 500 status for assets that do not compile due to an error?
I'd like to be able to write a test to ensure one of my SCSS assets can compile successfully, but it's difficult to do reliably do that by matching the body of the response. 我希望能够编写一个测试来确保我的SCSS资产之一可以成功编译,但是要通过匹配响应主体来可靠地做到这一点是很困难的。 I'd like to simply be able to check the response code when accessing the asset's URL, but it seems my app is returning a successful 200 status code even for assets that compile with errors.
我只希望能够在访问资产的URL时检查响应代码,但是即使对于有错误编译的资产,我的应用似乎也能成功返回200状态代码。 Observe:
观察:
$ curl -i http://domain/assets/my_asset.css
HTTP/1.1 200 OK
Content-Type: text/css;charset=utf-8
Content-Length: 1153
However, my logs clearly state that the asset does not compile OK: 但是,我的日志清楚地表明资产无法编译为OK:
Error compiling asset my_asset.css:
Sass::SyntaxError: Undefined variable: "$var".
Served asset /my_asset.css - 500 Internal Server Error
And the asset body does contain the error message, so I know it's serving up a "bad" asset, but the status code does not reflect that. 而且资产主体确实包含错误消息,因此我知道它正在提供“不良”资产,但是状态代码不能反映这一点。
Is there any way I can make my app return a 500 in this case? 在这种情况下,有什么方法可以使我的应用返回500?
Curl is used to transfer data from or to server. Curl用于从服务器传输数据或向服务器传输数据。 In case there exist previous versions of the same file it just gets the data.
如果存在相同文件的先前版本,则仅获取数据。
In case you want to know the status of the new version of the asset then add unique identity for the created asset or you have to remove the previous one before you create a new compilation (and make sure cache is expired in the server for the same asset). 如果您想知道资产新版本的状态,然后为创建的资产添加唯一标识,或者必须在创建新编译之前删除前一个资产(并确保相同服务器的缓存已过期)资产)。
Hope this helps. 希望这可以帮助。
Regards, HBK 问候,HBK
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.