|
35 | 35 | UnsavedChangesStrategy, |
36 | 36 | write_project_variables, |
37 | 37 | bytes_to_human_size, |
| 38 | + push_error_message, |
38 | 39 | ) |
39 | 40 | from .utils_auth import get_stored_mergin_server_url |
40 | 41 |
|
@@ -192,34 +193,7 @@ def create_project(self, project_name, project_dir, is_public, namespace): |
192 | 193 | dlg.exec() # blocks until success, failure or cancellation |
193 | 194 |
|
194 | 195 | if dlg.exception: |
195 | | - # push failed for some reason |
196 | | - if isinstance(dlg.exception, LoginError): |
197 | | - login_error_message(dlg.exception) |
198 | | - elif isinstance(dlg.exception, ClientError): |
199 | | - exc = dlg.exception |
200 | | - msg = str(exc) |
201 | | - |
202 | | - if exc.server_code == ErrorCode.StorageLimitHit.value: |
203 | | - data = exc.server_response |
204 | | - if isinstance(data, str): |
205 | | - try: |
206 | | - data = json.loads(data) |
207 | | - except json.JSONDecodeError: |
208 | | - data = {} |
209 | | - |
210 | | - storage_limit = data.get("storage_limit") |
211 | | - human_limit = bytes_to_human_size(storage_limit) if storage_limit is not None else "unknown" |
212 | | - |
213 | | - msg = f"{exc.detail}\nCurrent limit: {human_limit}" |
214 | | - |
215 | | - QMessageBox.critical(None, "Project sync", "Client error: " + msg) |
216 | | - else: |
217 | | - unhandled_exception_message( |
218 | | - dlg.exception_details(), |
219 | | - "Project sync", |
220 | | - f"Something went wrong while synchronising your project {project_name}.", |
221 | | - self.mc, |
222 | | - ) |
| 196 | + push_error_message(dlg, project_name, self.plugin, self.mc) |
223 | 197 | return True |
224 | 198 |
|
225 | 199 | if not dlg.is_complete: |
@@ -481,35 +455,7 @@ def sync_project(self, project_dir, project_name=None): |
481 | 455 | self.open_project(project_dir) |
482 | 456 |
|
483 | 457 | if dlg.exception: |
484 | | - # push failed for some reason |
485 | | - if isinstance(dlg.exception, LoginError): |
486 | | - login_error_message(dlg.exception) |
487 | | - elif isinstance(dlg.exception, ClientError): |
488 | | - if dlg.exception.http_error == 400 and "Another process" in dlg.exception.detail: |
489 | | - # To note we check for a string since error in flask doesn't return server error code |
490 | | - msg = "Somebody else is syncing, please try again later" |
491 | | - elif dlg.exception.server_code == ErrorCode.StorageLimitHit.value: |
492 | | - data = dlg.exception.server_response |
493 | | - if isinstance(data, str): |
494 | | - try: |
495 | | - data = json.loads(data) |
496 | | - except json.JSONDecodeError: |
497 | | - data = {} |
498 | | - storage_limit = data.get("storage_limit") |
499 | | - human_limit = bytes_to_human_size(storage_limit) if storage_limit is not None else "unknown" |
500 | | - msg = f"{dlg.exception.detail}\nCurrent limit: {human_limit}" |
501 | | - else: |
502 | | - msg = str(dlg.exception) |
503 | | - QMessageBox.critical(None, "Project sync", "Client error: \n" + msg) |
504 | | - elif isinstance(dlg.exception, AuthTokenExpiredError): |
505 | | - self.plugin.auth_token_expired() |
506 | | - else: |
507 | | - unhandled_exception_message( |
508 | | - dlg.exception_details(), |
509 | | - "Project sync", |
510 | | - f"Something went wrong while synchronising your project {project_name}.", |
511 | | - self.mc, |
512 | | - ) |
| 458 | + push_error_message(dlg, project_name, self.plugin, self.mc) |
513 | 459 | return |
514 | 460 |
|
515 | 461 | if dlg.is_complete: |
|
0 commit comments