15
15
class LambdaService (QObject ):
16
16
jsons_received = pyqtSignal (dict , dict )
17
17
validation_received = pyqtSignal (dict )
18
+ validation_failed = pyqtSignal ()
18
19
ActionAttribute = cast (QNetworkRequest .Attribute , QNetworkRequest .User + 1 )
19
20
ACTION_VALIDATE_PLANS = "validate_plans"
20
21
ACTION_GET_PLANS = "get_plans"
@@ -58,9 +59,12 @@ def _is_api_gateway_request(self) -> bool:
58
59
return bool (match )
59
60
60
61
def _handle_reply (self , reply : QNetworkReply ):
62
+ action = reply .request ().attribute (LambdaService .ActionAttribute )
61
63
if reply .error () != QNetworkReply .NoError :
62
64
error = reply .errorString ()
63
- QMessageBox .critical (None , "API Error" , f"Lambda call failed: { error } " )
65
+ QMessageBox .critical (None , "API Virhe" , f"Lambda kutsu epäonnistui: { error } " )
66
+ if action == self .ACTION_VALIDATE_PLANS :
67
+ self .validation_failed .emit ()
64
68
reply .deleteLater ()
65
69
return
66
70
@@ -72,20 +76,23 @@ def _handle_reply(self, reply: QNetworkReply):
72
76
# If calling the lambda directly, the response includes status code and body
73
77
if int (response_json .get ("statusCode" , 0 )) != HTTPStatus .OK :
74
78
error = response_json ["body" ] if "body" in response_json else response_json ["errorMessage" ]
75
- QMessageBox .critical (None , "API Error" , f"Lambda call failed: { error } " )
79
+ QMessageBox .critical (None , "API Virhe" , f"Lambda kutsu epäonnistui: { error } " )
80
+ if action == self .ACTION_VALIDATE_PLANS :
81
+ self .validation_failed .emit ()
76
82
reply .deleteLater ()
77
83
return
78
84
body = response_json ["body" ]
79
85
else :
80
86
body = response_json
81
87
82
88
except (json .JSONDecodeError , KeyError ) as e :
83
- QMessageBox .critical (None , "JSON Error" , f"Failed to parse response JSON: { e } " )
89
+ QMessageBox .critical (None , "JSON Virhe" , f"Vastauksen JSON-tiedoston jäsennys epäonnistui: { e } " )
90
+ if action == self .ACTION_VALIDATE_PLANS :
91
+ self .validation_failed .emit ()
84
92
return
85
93
finally :
86
94
reply .deleteLater ()
87
95
88
- action = reply .request ().attribute (LambdaService .ActionAttribute )
89
96
if action == self .ACTION_GET_PLANS :
90
97
self ._process_json_reply (body )
91
98
elif action == self .ACTION_VALIDATE_PLANS :
@@ -95,7 +102,6 @@ def _process_validation_reply(self, response_json: dict):
95
102
"""Processes the validation reply from the lambda and emits a signal."""
96
103
97
104
validation_errors = response_json .get ("ryhti_responses" )
98
-
99
105
self .validation_received .emit (validation_errors )
100
106
101
107
def _process_json_reply (self , response_json : dict ):
0 commit comments