add error logging for api endpoint