From 7c38a863a7ff17df591efcf8d6d86355ad60d0d9 Mon Sep 17 00:00:00 2001
From: Moul <moul@moul.re>
Date: Sun, 5 Jun 2022 16:43:07 +0200
Subject: [PATCH] [mypy] #163: verify: exit when failing to retrieve a chunk

Use urllib.error.HTTPError
Could fix #351, since 'None' (nothing) used to be returned
and the error was:
TypeError: 'NoneType' object is not subscriptable
---
 silkaj/blocks.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/silkaj/blocks.py b/silkaj/blocks.py
index 169f7a7d..5cdb3dd6 100644
--- a/silkaj/blocks.py
+++ b/silkaj/blocks.py
@@ -15,11 +15,11 @@
 
 import logging
 from typing import List
+from urllib.error import HTTPError
 
 from click import INT, argument, command, progressbar
 from duniterpy.api import bma
 from duniterpy.api.client import Client
-from duniterpy.api.errors import DuniterError
 from duniterpy.documents import Block
 
 from silkaj.constants import BMA_MAX_BLOCKS_CHUNK_SIZE
@@ -81,9 +81,11 @@ def get_chunk_size(
 
 def get_chunk(client: Client, chunk_size: int, chunk_from: int) -> List:
     try:
-        return client(bma.blockchain.blocks, chunk_size, chunk_from)
-    except DuniterError as error:
-        logging.error(error)
+        chunk = client(bma.blockchain.blocks, chunk_size, chunk_from)
+    except HTTPError as e:
+        logging.error(e)
+        message_exit("Error: Network error to get chunck")
+    return chunk
 
 
 def verify_block_signature(invalid_blocks_signatures: List[int], block: Block) -> None:
-- 
GitLab