add better error responses and logging