Refactor api logic, fix exception handling on some providers