diff --git a/import_md/hedgedoc_import.py b/import_md/hedgedoc_import.py index 9ee907cf3b6539303cbe55507638e1bca4295af8..971e9b37afbabfe9c8d207e0d298d04f8851aade 100644 --- a/import_md/hedgedoc_import.py +++ b/import_md/hedgedoc_import.py @@ -17,7 +17,11 @@ def import_single_document(instance_url, hedgedoc_free_url, content, session_id) req = urllib.request.Request(request_url, data=str.encode(content), method='POST', headers=headers) # unfortunately, no error is thrown if a document is not created when session cookie is invalid + # HTTP 409 is ignored for the sake of simplicity. Handled in import_into_hedgedoc(..) + # Not optimal, but nobody ain't got time for that with urllib.request.urlopen(req) as response: + if response.url == instance_url + "/": + raise SystemExit("Could not import document. Please check your HedgeDoc session cookie. Aborting...") return response.url @@ -75,8 +79,9 @@ def process_archive_export(archive_file, instance_url, lookup_map, session_id, u try_generate_free_url_document(document_content, document_title, instance_url, lookup_map, session_id, urls_to_visit) else: - print(f"According to your history, you did not visit \"{document_title}.md\" in the CodiMD " - "instance recently. Migrating the document and generating a new, random URL/path for it") + print( + f"According to your history (or lack thereof) , you did not visit \"{document_title}.md\" in the " + f"CodiMD instance recently. Migrating the document and generating a new, random URL/path for it") # empty string implies HedgeDoc should create a new ID generated_url = import_single_document(instance_url, "", document_content, session_id) print(f"New URL after document migration with new, random URL/subpath: "