IBM / watson-assistant-workbench

Framework for maintaining Watson Assistant data in github repository with bundle of tools for generating, testing and uploading. Travis: https://travis-ci.com/IBM/watson-assistant-workbench. Artifactory (will be deleted after 25 Nov 2019): https://na.artifactory.swg-devops.com/artifactory/webapp/#/artifacts/browse/tree/General/iot-waw-trevis-generic-local.
Apache License 2.0
16 stars 25 forks source link

Unify approach to response status codes #316

Open Tereza-Pytelova opened 5 years ago

Kseii commented 5 years ago

Our approach now:

response = requests.qet(url)
responseJson = response.json()
if 'error' in responseJson:
    sys.exit(1)

The problem is, that the response might not even have any JSON in it. A better approach is to do:

response = requests.qet(url)
response.raise_for_status()

This raises an exception if the status of the response is 400 and higher. If the request is successful, the script continues.