Fix indentation of JS generated code & handle exceptions in a cleaner manner