Add simple test for extracting error title

CURA-7959
This commit is contained in:
Jaime van Kessel 2021-04-26 11:38:59 +02:00
parent 32ec72a28c
commit cf8113608f
No known key found for this signature in database
GPG key ID: 3710727397403C91
3 changed files with 39 additions and 1 deletions

View file

@ -2,6 +2,7 @@
# Cura is released under the terms of the LGPLv3 or higher.
import json
import threading
from json import JSONDecodeError
from typing import List, Dict, Any, Callable, Union, Optional
from PyQt5.QtCore import QUrl
@ -271,7 +272,11 @@ class DFFileExportAndUploadManager:
def extractErrorTitle(reply_body: Optional[str]) -> str:
error_title = ""
if reply_body:
reply_dict = json.loads(reply_body)
try:
reply_dict = json.loads(reply_body)
except JSONDecodeError:
Logger.logException("w", "Unable to extract title from reply body")
return error_title
if "errors" in reply_dict and len(reply_dict["errors"]) >= 1 and "title" in reply_dict["errors"][0]:
error_title = reply_dict["errors"][0]["title"]
return error_title