varfish-org / varfish-cli

VarFish REST API client (CLI + Python package)
MIT License
2 stars 3 forks source link

Catch 400 VarFish server response #5

Closed stolpeo closed 2 years ago

stolpeo commented 2 years ago

Is your feature request related to a problem? Please describe. When trying to import a case to a category or listing the content of a category, VarFish throws now a 400 error. This should be handled by the varfish-cli. Currently the error message is cryptic for the user:

$ varfish-cli case list-import-info 170ed9f8-630b-4ce6-a3f5-928383a9b7f4
[I 211203 16:19:47] Configuration: CaseListImportInfoConfig(case_config=CaseConfig(global_config=CommonConfig(verbose=False, verify_ssl=True, varfish_api_token='4c2d************************************************************', varfish_server_url='http://localhost:8000/')), project_uuid=UUID('170ed9f8-630b-4ce6-a3f5-928383a9b7f4'), owner=None)
[I 211203 16:19:47] Listing cases
Traceback (most recent call last):
  File "/home/oliver/.local/bin/varfish-cli", line 11, in <module>
    load_entry_point('varfish-cli', 'console_scripts', 'varfish-cli')()
  File "/home/oliver/dev/varfish-cli/varfish_cli/__main__.py", line 109, in main
    res = cmds[args.cmd](
  File "/home/oliver/dev/varfish-cli/varfish_cli/case/__init__.py", line 31, in run
    return args.case_cmd(config, toml_config, args, parser, subparser)
  File "/home/oliver/dev/varfish-cli/varfish_cli/case/list_case_import.py", line 27, in run
    res = api.case_import_info_list(
  File "/home/oliver/dev/varfish-cli/varfish_cli/api/case.py", line 123, in case_import_info_list
    " ".join([" ".join(v) for v in result.json().values()]),
AttributeError: 'list' object has no attribute 'values'

Describe the solution you'd like The response by the server should be caught and a proper error message should be displayed, like "Pushing case failed" (probably the reason might not be visible as VarFish itself isn't descriptive itself.

Describe alternatives you've considered None.

Additional context On VarFish side it looks like this:

Bad Request: /importer/api/case-import-info/170ed9f8-630b-4ce6-a3f5-928383a9b7f4/
[03/Dec/2021 15:19:47] "GET /importer/api/case-import-info/170ed9f8-630b-4ce6-a3f5-928383a9b7f4/ HTTP/1.1" 400 58
stolpeo commented 2 years ago

This was a minor bug in the SODAR core implementation, which is solved. Now a 403 gets returned and a JSON dict instead of a list, such that the error message can be displayed with the current code.