From c62ca5412f0fbf50cc8124e5638544f1346e5f7f Mon Sep 17 00:00:00 2001
From: vuillaut <thomas.vuillaume@gmail.com>
Date: Thu, 30 Sep 2021 21:36:45 +0200
Subject: [PATCH] raise error if entry not created

---
 eossr/scripts/eossr_upload_new_deposit.py | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/eossr/scripts/eossr_upload_new_deposit.py b/eossr/scripts/eossr_upload_new_deposit.py
index 29d2b7f6..42a778d1 100644
--- a/eossr/scripts/eossr_upload_new_deposit.py
+++ b/eossr/scripts/eossr_upload_new_deposit.py
@@ -55,21 +55,18 @@ def upload(zenodo_token, sandbox_flag, input_directory):
 
     # 1 - create empty deposit
     new_entry = zenodo.create_new_entry()
+    ZenodoHTTPStatus(new_entry.status_code, new_entry.json())
+
+    record_id = new_entry.json()['id']
+    print(f" * Status {new_entry.status_code}. New entry to Zenodo created ! Deposition id {record_id}")
 
-    if new_entry.status_code < 399:
-        deposition_id = new_entry.json()['id']
-        doi = new_entry.json()['metadata']['prereserve_doi']['doi']
-        print(f" * Status {new_entry.status_code}. New entry to Zenodo created ! Deposition id {deposition_id}")
-    else:
-        print(f" ! ERROR; the NEW entry COULD NOT be created.")
-        print(new_entry.json())
 
     # 2 - upload files
     for file in os.listdir(input_directory):
         full_path_file = input_directory + '/' + file
 
         new_upload = zenodo.upload_file_entry(
-            deposition_id,
+            record_id,
             name_file=file,
             path_file=full_path_file
         )
@@ -88,7 +85,7 @@ def upload(zenodo_token, sandbox_flag, input_directory):
 
     # entry_info['metadata']['doi'] = doi  # In the new version of the API the doi is updated automatically.
     update_entry = zenodo.update_metadata_entry(
-        deposition_id,
+        record_id,
         json_metadata=entry_metadata
     )
 
@@ -97,12 +94,12 @@ def upload(zenodo_token, sandbox_flag, input_directory):
 
 
     # 4 - publish entry
-    publish = zenodo.publish_entry(deposition_id)
+    publish = zenodo.publish_entry(record_id)
 
     if publish.status_code == 204:
         print(" * New deposit correctly published !\n")
-        print(f" * The new doi should look like 10.5281/{deposition_id}. However please")
-        print(f" ** Check the upload at {zenodo.zenodo_api_url[:-4]}/deposit/{deposition_id}  **")
+        print(f" * The new doi should look like 10.5281/{record_id}. However please")
+        print(f" ** Check the upload at {zenodo.zenodo_api_url[:-4]}/deposit/{record_id}  **")
     else:
         print(f" ! New deposit NOT correctly published ! Status {publish.status_code}\n",
               publish.json())
-- 
GitLab