Refactor the way to deal with exception in rails