Skip to content

Commit 6b6e4d4

Browse files
committed
update error exception and request porccesor and model changes
1 parent 8299fbe commit 6b6e4d4

File tree

6 files changed

+50
-1
lines changed

6 files changed

+50
-1
lines changed

request-processor/src/application/core/pipeline.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ def fetch_add_data_response(
210210

211211
existing_entities = []
212212
new_entities = []
213+
entity_org_mapping = []
213214
issues_log = None
214215

215216
for idx, resource_file in enumerate(files_in_resource):
@@ -260,6 +261,12 @@ def fetch_add_data_response(
260261
)
261262
new_entities.extend(new_lookups)
262263

264+
# Default create a entity-organisation mapping, front end can use the 'authoritative' flag
265+
entity_org_mapping = create_entity_organisation(
266+
new_lookups, dataset, organisation_provider
267+
)
268+
# TODO, save to pipeline as well for rerun?
269+
263270
# Reload pipeline to pick up newly saved lookups
264271
pipeline = Pipeline(
265272
pipeline_dir, dataset, specification=specification
@@ -293,6 +300,7 @@ def fetch_add_data_response(
293300
"existing-in-resource": len(existing_entities),
294301
"new-entities": new_entities_breakdown,
295302
"existing-entities": existing_entities_breakdown,
303+
"entity-organisation": entity_org_mapping,
296304
"pipeline-issues": [dict(issue) for issue in issues_log.rows]
297305
if issues_log
298306
else [],
@@ -354,6 +362,38 @@ def _get_existing_entities_breakdown(existing_entities):
354362
return breakdown
355363

356364

365+
def create_entity_organisation(new_entities, dataset, organisation):
366+
"""
367+
Create entity-organisation mapping from new entities.
368+
369+
Args:
370+
new_entities: List of entity dicts with 'entity' key
371+
dataset: Dataset name
372+
organisation: Organisation identifier
373+
374+
Returns:
375+
List with single dict containing dataset, entity-minimum, entity-maximum, organisation
376+
"""
377+
if not new_entities:
378+
return []
379+
380+
entity_values = [
381+
entry.get("entity") for entry in new_entities if entry.get("entity")
382+
]
383+
384+
if not entity_values:
385+
return []
386+
387+
return [
388+
{
389+
"dataset": dataset,
390+
"entity-minimum": min(entity_values),
391+
"entity-maximum": max(entity_values),
392+
"organisation": organisation,
393+
}
394+
]
395+
396+
357397
def _map_transformed_entities(transformed_csv_path, pipeline_dir): # noqa: C901
358398
"""Extract unique entities from transformed CSV and lookup their details in lookup.csv."""
359399

request-processor/src/application/core/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,11 @@ def create_user_friendly_error_log(exception_detail):
251251
status_code = exception_detail.get("errCode")
252252
exception_type = exception_detail.get("exceptionType")
253253
content_type = exception_detail.get("contentType")
254+
plugin = exception_detail.get("plugin")
254255

255256
user_message = "An error occurred, please try again later."
256257

258+
# The ordering here has been considered to show the most relevant message to users in the front end
257259
if exception_type in ["SSLError", "SSLCertVerificationError"]:
258260
user_message = "SSL certificate verification failed"
259261
elif content_type and "text/html" in content_type:
@@ -264,6 +266,8 @@ def create_user_friendly_error_log(exception_detail):
264266
user_message = "The URL must be accessible"
265267
elif status_code == "404":
266268
user_message = "The URL does not exist. Check the URL you've entered is correct (HTTP 404 error)"
269+
elif plugin == "arcgis" and status_code == "200":
270+
user_message = "URL must be the data layer"
267271

268272
result = dict(exception_detail)
269273
result["message"] = user_message

request-processor/src/application/exceptions/customExceptions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ def __init__(self, log={}):
4444
# Content type of the response useful for text/html checks (when not using arcgis/wfs plugin)
4545
self.content_type = log.get("content-type")
4646
self.message_detail = log.get("user_message_detail")
47+
self.plugin = log.get("plugin")
4748

4849
self.load()
4950
super().__init__(self.detail)
5051

5152
def load(self):
53+
# This is not the best way to do this but keeps backward compatibility for now
5254
self.detail = {
5355
"errCode": str(self.status) if self.status is not None else None,
5456
"errType": "User Error",
@@ -60,4 +62,5 @@ def load(self):
6062
"fetchStatus": self.fetch_status,
6163
"exceptionType": self.exception_type,
6264
"contentType": self.content_type,
65+
"plugin": self.plugin,
6366
}

request-processor/src/tasks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ def _fetch_resource(resource_dir, url):
513513
}
514514
)
515515
elif log.get("exception") or log.get("status", "").startswith("4"):
516+
log["plugin"] = plugin # Save plugin used for arcgis error context
516517
break
517518

518519
# All fetch attempts failed - include content-type if available

request_model/schemas.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class AddDataParams(Params):
3838
type: Literal[RequestTypeEnum.add_data] = RequestTypeEnum.add_data
3939
url: Optional[str] = None
4040
documentation_url: Optional[str] = None
41+
authoritative: Optional[bool] = None
4142
licence: Optional[str] = None
4243
start_date: Optional[str] = None
4344
organisation: Optional[str] = None

scripts/debug_trigger_add_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def ensure_request_exists(request_payload: dict) -> None:
9393
"collection": "article-4-direction",
9494
"column_mapping": None,
9595
"geom_type": None,
96-
"url": "https://smbc-opendata.s3.eu-west-1.amazonaws.com/Article4/Article4_Dataset_Stockport.csv",
96+
"url": "https://raw.githubusercontent.com/digital-land/PublishExamples/refs/heads/main/Article4Direction/Files/Article4DirectionArea/articel4directionareas-(wrongColName-NewRefs).csv",
9797
"documentation_url": "https://example.com/article-4-direction/documentation",
9898
"licence": "ogl3",
9999
"start_date": "2020-01-01",

0 commit comments

Comments
 (0)