Added exception handling for api