More exception handling at js and php level