Created
May 13, 2018 14:05
-
-
Save searls/e573d885adf24402bf4c31df7ee98207 to your computer and use it in GitHub Desktop.
Sometimes I find it handy when I'm developing a single page app to have all front-end errors forwarded to the backend's log (when something doesn't work, I can look in a single terminal window)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const puts = (...anything) => { | |
fetch("/api/puts", { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({content: anything}) | |
}) | |
} | |
window.onerror = (message) => { | |
puts('JS Error:', message) | |
return false | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Api | |
class PutsController < ApiController | |
def create | |
puts <<~TEXT | |
Client logger says: | |
#{params[:content].map(&:to_json).join(", ")} | |
TEXT | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment