properly handle error response