Fixed main error handling issue in api