fix exception if response is not successful

Please refer to the above comment