add error type code to HTML for convenience when adding custom error messages (#654)
This commit is contained in:
parent
e51638948f
commit
d88d3505ec
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue