Added error logging to API