From a4d94eb40ab52ffbc9f1e9647d5cc29edae18905 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Sun, 27 Nov 2022 16:54:08 +0900 Subject: feat: Initialise Errors dictionary in constructor This mitigates a possible NRE if no errors has been added --- code/api/src/Data/Models/KnownProblemModel.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'code/api/src/Data/Models/KnownProblemModel.cs') diff --git a/code/api/src/Data/Models/KnownProblemModel.cs b/code/api/src/Data/Models/KnownProblemModel.cs index 818a295..9acc85c 100644 --- a/code/api/src/Data/Models/KnownProblemModel.cs +++ b/code/api/src/Data/Models/KnownProblemModel.cs @@ -5,7 +5,7 @@ public class KnownProblemModel public KnownProblemModel(string title = default, string subtitle = default, Dictionary errors = default) { Title = title; Subtitle = subtitle; - Errors = errors; + Errors = errors ?? new(); } public string Title { get; set; } @@ -14,10 +14,6 @@ public class KnownProblemModel public string TraceId { get; set; } public void AddError(string field, string errorText) { - if (Errors == default) { - Errors = new Dictionary(); - } - if (!Errors.ContainsKey(field)) { Errors.Add(field, new[] {errorText}); } else { -- cgit v1.3