better exception handling with http response code