[doc] handle api errors in python client

This commit is contained in:
Julien Vehent 2015-01-26 09:26:44 -05:00
Родитель 5018b916c0
Коммит b7b1cd1961
1 изменённых файлов: 3 добавлений и 2 удалений

Просмотреть файл

@ -33,12 +33,13 @@ if __name__ == '__main__':
if r.status_code == 200: if r.status_code == 200:
print json.dumps(r.json(), sort_keys=True, indent=4, separators=(',', ': ')) print json.dumps(r.json(), sort_keys=True, indent=4, separators=(',', ': '))
elif r.status_code == 500: elif r.status_code == 500:
print r.json()
# api returns a 500 with an error body on failures # api returns a 500 with an error body on failures
migjson=r.json() migjson=r.json()
raise Exception("API returned HTTP code %s and error '%s:%s'" % raise Exception("API returned HTTP code %s and error '%s:%s'" %
(r.status_code, (r.status_code,
migjson['collection']['code'], migjson['collection']['error']['code'],
migjson['collection']['message']) migjson['collection']['error']['message'])
) )
else: else:
# another type of failure that's unlikely to have an error body # another type of failure that's unlikely to have an error body