Rails Api Error Handling In Javascript