Clojure Ring auto-refresh script for error screen - clojure

When :auto-reload? true, Ring injects an auto refresh <script> tag via its internal wrap-reload middleware whenever you return a status full HTML page. However, this auto-refresh script is not included when an error occurs. As a result, I have to manually refresh the page.
How can I tell Ring to inject an auto-refresh script into its error screen as well?
This is in my project.clj:
:ring {:handler my-app.handler/app
:auto-reload? true
:auto-refresh? true}

Since the auto-refresh is added to the successful response, perhaps it needs to also be added to the error response. You could add a custom error response that returns a 500 error whose body includes the auto refresh script.

Related

django error reporting request url - how to use this locally?

I have a django project which used the normal email admins on an unhandled exception when debug is set to False. ie in production.
I normally just review the error message and the stack trace. However I clicked on the request url link, which managed to recreate the error on the prouduction site (which then fired off another email).
What is this request url? Does it recreate the full http request (including the session etc..) which resulted in the original error?
Can I get the link to point to a local version of the site? (As after fixing a previous error clicking on the earlier request url has manged to create a recent error that we have been unable to reproduce, so it would be good to recreate this locally so it can be debugged.

In ClojureScript, why can't I navigate to a URL entered by hand, but if I click a link it works?

(Note, I'm using Reagent, Secretary, and Compojure (among others))
I want to create a route /sectest/:id, and if I point my browser to that route, I get the following error:
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:3449/sectest/css/site.css".
asdf:1
Refused to execute script from 'http://localhost:3449/sectest/js/app.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
But if I click on a link in the browser that navigates to that route, it works fine...
Here's the pertinent code:
Client Side:
(secretary/defroute "/sectest/:id" [id]
(do
(js/console.log (str "Hi " id))
(session/put! :current-page #'my-page)))
Server Side:
(defroutes routes
(GET "*" [] loading-page) ;this anticipates client-side routing only
(GET "/cards" [] cards-page)
(resources "/")
(not-found "Not Found"))
(def app (wrap-middleware #'routes))
So the following link takes me to my-page, and the console prints "Hi asdf" just fine:
[:div [:a {:href "/sectest/asdf"} "SECTEST"]]
But if I type in http://localhost:3449/sectest/asdf, I get an error, and I can't seem to trace it. I suspect it might have something to do with the code trying to find resources located at /sectest, (which it shouldn't), but I can't confirm this or figure out how to work with it... I am new to clojure, so forgive if I'm massively ignorant on some point, any thoughts?
Take a look at your server side routing, effectively you only have one route:
(GET "*" [] loading-page)
As it handles everything all following routes will never trigger. Order matters:
(defroutes routes
(GET "/cards" [] cards-page)
(resources "/")
(GET "*" [] loading-page) ;this anticipates client-side routing only
)
The above should do the trick, I removed the 404 route, as this should be handled by the frontend routing.
The reason it currently works when clicking on a page link in your SPA is that it will get handled by secretary. If you enter the url manually you are doing a page reload and the request is handled by compojure initially.
Edit:
After taking a closer look, relative links to your css/js files in your html template are most likely the culprit here:
/sectest/js/app.js
The compojure resources route won't match and the default catch all route loading-page is served as css/js file to your browser. Hence the error.
For my dev env I also had to correct the :asset-path of my boot cljs task as the source mapping files suffered from the problem. Should be similiar with lein-figwheel.

Boot: serve non-root directory from classpath in handler + cljs reload

I have tried to convert a leiningen project to boot: https://github.com/borkdude/lein2boot.
It uses the serve task to serve a handler. The handler offers an API and also serves files. Using the reload task, I want to be able to reload javascript.
I needed to place my html and javascript at the root of a resources directory (in this example "assets"), because the reload task sends changed javascript to the browser using the full resource path (/main.js).
This means I also have to serve the root of my classpath: (resources "/" {:root ""}) in Compojure. The problem with this is that anyone can request any file from my entire classpath: no good.
When I relocate the javascript to assets/public/main.js and serve from the public directory: (resources "/" {:root "public"}), the file can be requested at "/main.js", but the reload task notifies the browser to reload a file from "/public/main.js" which causes a 404.
How can I solve this problem?
It looks like this is being worked on in https://github.com/adzerk-oss/boot-reload/issues/18, but will eventually allow an :asset-path option to provide relative roots.

poltergeist onConsoleMessage initialization on Capybara

I'm using the phantomjs driver via poltergeist on ruby/capybara. One thing I'm trying to setup is the ability of receiving debug messages from javascript into the ruby debug console.
I see that phantomjs has a javascript OnConsoleMessage callback to set up this, but I couldn't find a way to wire this up from ruby. Any ideas?
Ok, it seems that you need to enable the inspector
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, {debug: true, :timeout => 90, :inspector => true})
end
Capybara.javascript_driver = :poltergeist
and then place
page.driver.debug
somewhere on the spec, which will bring a link to the inspector dashboard. It doesn't reload by default, so you need to hit reload from time to time to see changes

Debuging of 500 http response

I need to fix some issues on an application written in Tornado. It is REST canvas app which use socket to communicate with the server. Sometimes it generates 500 error when user tries to logout during some nodes' loading. I tried to replace 500 response with 402 type by using Try block in certain handler, but I am still getting 500 in the client. So I need to get exact line of Python code that generates error. Unfortunately I am not sure how to check those as all my browser is showing is 500 error, that's it.
If you start your application from the command line and then trigger the HTTP 500 error, you should see a traceback written to the console. Or at least it will appear in the log file.
Or, update the code that creates the tornado.web.Application instance in your application's main file, and pass debug=True to the Application() constructor. That turns on several options including serve_traceback. Then you should see a full traceback in the error response, not just a "500".