Refactor error handling when rendering in browser