Move JS error handler code