summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-08-06 01:16:55 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-09-14 19:05:59 -0400
commitd88d3505ec75c3633cdd5d57058a5d290e558dfb (patch)
tree2dcab084db69b491998b51efa43d7a6b3fc65090
parente51638948f4355c27d6b3f02d637d4ed754ccb73 (diff)
downloadSMAPI-d88d3505ec75c3633cdd5d57058a5d290e558dfb.tar.gz
SMAPI-d88d3505ec75c3633cdd5d57058a5d290e558dfb.tar.bz2
SMAPI-d88d3505ec75c3633cdd5d57058a5d290e558dfb.zip
add error type code to HTML for convenience when adding custom error messages (#654)
-rw-r--r--src/SMAPI.Web/Controllers/JsonValidatorController.cs4
-rw-r--r--src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs9
-rw-r--r--src/SMAPI.Web/Views/JsonValidator/Index.cshtml2
3 files changed, 11 insertions, 4 deletions
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<ValidationError> 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
{
/// <summary>The view model for a JSON validator error.</summary>
@@ -15,6 +17,9 @@ namespace StardewModdingAPI.Web.ViewModels.JsonValidator
/// <summary>A human-readable description of the error.</summary>
public string Message { get; set; }
+ /// <summary>The schema error type.</summary>
+ public ErrorType SchemaErrorType { get; set; }
+
/*********
** Public methods
@@ -26,11 +31,13 @@ namespace StardewModdingAPI.Web.ViewModels.JsonValidator
/// <param name="line">The line number on which the error occurred.</param>
/// <param name="path">The field path in the JSON file where the error occurred.</param>
/// <param name="message">A human-readable description of the error.</param>
- public JsonValidatorErrorModel(int line, string path, string message)
+ /// <param name="schemaErrorType">The schema error type.</param>
+ 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)
{
- <tr>
+ <tr data-schema-error="@error.SchemaErrorType">
<td><a href="#L@(error.Line)">@error.Line</a></td>
<td>@error.Path</td>
<td>@error.Message</td>