add error type code to HTML for convenience when adding custom error messages (#654)

This commit is contained in:
Jesse Plamondon-Willard 2019-08-06 01:16:55 -04:00
parent e51638948f
commit d88d3505ec
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
3 changed files with 11 additions and 4 deletions

View File

@ -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));
}

View File

@ -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;
}
}
}

View File

@ -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>