openearth / hydro-engine

Hydro Engine is a service and a command-line tool to query static and dynamic hydrographic data derived from Earth Observations
MIT License
30 stars 9 forks source link

add try except around requests #24

Closed visr closed 6 years ago

visr commented 6 years ago

With this users can get an idea of what went wrong, showing the requests error followed by the server response, with a full traceback after:

500 Server Error: INTERNAL SERVER ERROR for url: http://hydro-engine.appspot.com/get_raster
{
  "error": {
    "message": "'dtm'",
    "type": "UnexpectedException"
  },
  "success": false
}

Traceback (most recent call last):
  File "c:\bin\Miniconda3\envs\wflow3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\bin\Miniconda3\envs\wflow3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "d:\repo\hydro-model-builder\hydro_model_builder\cli.py", line 72, in <module>
    main(sys.argv[1:])  # pragma: no cover
  File "c:\bin\Miniconda3\envs\wflow3\lib\site-packages\click\core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "c:\bin\Miniconda3\envs\wflow3\lib\site-packages\click\core.py", line 697, in main
    rv = self.invoke(ctx)
  File "c:\bin\Miniconda3\envs\wflow3\lib\site-packages\click\core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\bin\Miniconda3\envs\wflow3\lib\site-packages\click\core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\bin\Miniconda3\envs\wflow3\lib\site-packages\click\core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "d:\repo\hydro-model-builder\hydro_model_builder\cli.py", line 34, in generate_model
    general_options(genopt)
  File "d:\repo\hydro-model-builder\hydro_model_builder\cli.py", line 57, in general_options
    get_hydro_data(region, ds)
  File "d:\repo\hydro-model-builder\hydro_model_builder\cli.py", line 48, in get_hydro_data
    ds["catchment_level"],
  File "d:\repo\hydro-engine\src\py\hydroengine\hydroengine.py", line 126, in download_raster
    raise e
  File "d:\repo\hydro-engine\src\py\hydroengine\hydroengine.py", line 121, in download_raster
    r.raise_for_status()
  File "c:\bin\Miniconda3\envs\wflow3\lib\site-packages\requests\models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: INTERNAL SERVER ERROR for url: http://hydro-engine.appspot.com/get_raster
gena commented 6 years ago

Oops, I meant for the server-side. It looks fine for the client-side, only needs to be extracted into a separate function to avoid repetition.

visr commented 6 years ago

Made it a separate function now