1
1
from flask import Blueprint , jsonify , request
2
- from werkzeug .exceptions import BadRequest
2
+ from werkzeug .exceptions import BadRequest , NotImplemented
3
3
4
4
from pydatalab .apps import BLOCK_TYPES
5
5
from pydatalab .blocks .base import DataBlock
@@ -26,12 +26,8 @@ def add_data_block():
26
26
insert_index = request_json ["index" ]
27
27
28
28
if block_type not in BLOCK_TYPES :
29
- return (
30
- jsonify (
31
- status = "error" ,
32
- message = f"Invalid block type { block_type !r} , must be one of { BLOCK_TYPES .keys ()} " ,
33
- ),
34
- 400 ,
29
+ raise NotImplemented ( # noqa
30
+ f"Invalid block type { block_type !r} , must be one of { BLOCK_TYPES .keys ()} "
35
31
)
36
32
37
33
block = BLOCK_TYPES [block_type ](item_id = item_id )
@@ -92,7 +88,9 @@ def add_collection_data_block():
92
88
insert_index = request_json ["index" ]
93
89
94
90
if block_type not in BLOCK_TYPES :
95
- return jsonify (status = "error" , message = "Invalid block type" ), 400
91
+ raise NotImplemented ( # noqa
92
+ f"Invalid block type { block_type !r} , must be one of { BLOCK_TYPES .keys ()} "
93
+ )
96
94
97
95
block = BLOCK_TYPES [block_type ](collection_id = collection_id )
98
96
@@ -169,7 +167,7 @@ def _save_block_to_db(block: DataBlock) -> None:
169
167
170
168
if result .matched_count != 1 :
171
169
raise BadRequest (
172
- f"_Failed to save block , likely because item_id ({ block .data .get ('item_id' )} ), collection_id ({ block .data .get ('collection_id' )} ) and/or block_id ({ block .block_id } ) wasn't found"
170
+ f"_save_block_to_db failed , likely because item_id ({ block .data .get ('item_id' )} ), collection_id ({ block .data .get ('collection_id' )} ) and/or block_id ({ block .block_id } ) wasn't found"
173
171
)
174
172
175
173
@@ -183,9 +181,14 @@ def update_block():
183
181
request_json = request .get_json ()
184
182
block_data = request_json ["block_data" ]
185
183
event_data = request_json .get ("event_data" , None )
186
- blocktype = block_data ["blocktype" ]
184
+ block_type = block_data ["blocktype" ]
185
+
186
+ if block_type not in BLOCK_TYPES :
187
+ raise NotImplemented ( # noqa
188
+ f"Invalid block type { block_type !r} , must be one of { BLOCK_TYPES .keys ()} "
189
+ )
187
190
188
- block = BLOCK_TYPES [blocktype ].from_web (block_data )
191
+ block = BLOCK_TYPES [block_type ].from_web (block_data )
189
192
190
193
if event_data :
191
194
try :
0 commit comments