简体   繁体   中英

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. 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. 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:

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?

Curl is used to transfer data from or to server. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM