From 5e8b4ea0e088475edb088ea052fc8f6c9ae67c90 Mon Sep 17 00:00:00 2001 From: karolina-siemieniuk-morawska Date: Thu, 25 Jan 2024 14:34:50 +0100 Subject: [PATCH] fix undefined property error * ref: cern-sis/issues-inspire#424 --- .../services/compare-keys-by-schema.service.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/shared/services/compare-keys-by-schema.service.ts b/src/shared/services/compare-keys-by-schema.service.ts index 70548ebd..2afbf0f7 100644 --- a/src/shared/services/compare-keys-by-schema.service.ts +++ b/src/shared/services/compare-keys-by-schema.service.ts @@ -34,11 +34,21 @@ export class CompareKeysBySchemaService { */ compare(key1: string, key2: string, schema: JSONSchema): number { // Sort by priority, larger is the first. - const priorty1 = schema.properties[key1].priority || 0; - const priority2 = schema.properties[key2].priority || 0; + const priority1 = + (schema && + schema.properties && + schema.properties[key1] && + schema.properties[key1].priority) || + 0; + const priority2 = + (schema && + schema.properties && + schema.properties[key2] && + schema.properties[key2].priority) || + 0; - if (priorty1 > priority2) { return -1; } - if (priorty1 < priority2) { return 1; } + if (priority1 > priority2) { return -1; } + if (priority1 < priority2) { return 1; } // Sort alphabetically. if (key1 < key2) { return -1; }