From d88d3505ec75c3633cdd5d57058a5d290e558dfb Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 6 Aug 2019 01:16:55 -0400 Subject: add error type code to HTML for convenience when adding custom error messages (#654) --- src/SMAPI.Web/Controllers/JsonValidatorController.cs | 4 ++-- .../ViewModels/JsonValidator/JsonValidatorErrorModel.cs | 9 ++++++++- src/SMAPI.Web/Views/JsonValidator/Index.cshtml | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/SMAPI.Web/Controllers/JsonValidatorController.cs b/src/SMAPI.Web/Controllers/JsonValidatorController.cs index cc2a7add..c23103dd 100644 --- a/src/SMAPI.Web/Controllers/JsonValidatorController.cs +++ b/src/SMAPI.Web/Controllers/JsonValidatorController.cs @@ -99,7 +99,7 @@ namespace StardewModdingAPI.Web.Controllers } catch (JsonReaderException ex) { - return this.View("Index", result.AddErrors(new JsonValidatorErrorModel(ex.LineNumber, ex.Path, ex.Message))); + return this.View("Index", result.AddErrors(new JsonValidatorErrorModel(ex.LineNumber, ex.Path, ex.Message, ErrorType.None))); } // format JSON @@ -124,7 +124,7 @@ namespace StardewModdingAPI.Web.Controllers // validate JSON parsed.IsValid(schema, out IList rawErrors); var errors = rawErrors - .Select(error => new JsonValidatorErrorModel(error.LineNumber, error.Path, this.GetFlattenedError(error))) + .Select(error => new JsonValidatorErrorModel(error.LineNumber, error.Path, this.GetFlattenedError(error), error.ErrorType)) .ToArray(); return this.View("Index", result.AddErrors(errors)); } diff --git a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs index f9497a38..62b95501 100644 --- a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs +++ b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs @@ -1,3 +1,5 @@ +using Newtonsoft.Json.Schema; + namespace StardewModdingAPI.Web.ViewModels.JsonValidator { /// The view model for a JSON validator error. @@ -15,6 +17,9 @@ namespace StardewModdingAPI.Web.ViewModels.JsonValidator /// A human-readable description of the error. public string Message { get; set; } + /// The schema error type. + public ErrorType SchemaErrorType { get; set; } + /********* ** Public methods @@ -26,11 +31,13 @@ namespace StardewModdingAPI.Web.ViewModels.JsonValidator /// The line number on which the error occurred. /// The field path in the JSON file where the error occurred. /// A human-readable description of the error. - public JsonValidatorErrorModel(int line, string path, string message) + /// The schema error type. + public JsonValidatorErrorModel(int line, string path, string message, ErrorType schemaErrorType) { this.Line = line; this.Path = path; this.Message = message; + this.SchemaErrorType = schemaErrorType; } } } diff --git a/src/SMAPI.Web/Views/JsonValidator/Index.cshtml b/src/SMAPI.Web/Views/JsonValidator/Index.cshtml index 1cf35e39..6e5da7e5 100644 --- a/src/SMAPI.Web/Views/JsonValidator/Index.cshtml +++ b/src/SMAPI.Web/Views/JsonValidator/Index.cshtml @@ -111,7 +111,7 @@ else if (Model.PasteID != null) @foreach (JsonValidatorErrorModel error in Model.Errors) { - + @error.Line @error.Path @error.Message -- cgit