diff --git a/Build.ps1 b/Build.ps1 index 9a5e17d170..6a37b7f8a5 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -1,3 +1,14 @@ +# Gets the version suffix from the repo tag +# example: v1.0.0-preview1-final => preview1-final +function Get-Version-Suffix-From-Tag +{ + $tag=$env:APPVEYOR_REPO_TAG_NAME + $split=$tag -split "-" + $suffix=$split[1..2] + $final=$suffix -join "-" + return $final +} + $revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; $revision = "{0:D4}" -f [convert]::ToInt32($revision, 10) @@ -10,13 +21,16 @@ dotnet test ./test/NoEntityFrameworkTests/NoEntityFrameworkTests.csproj dotnet build .\src\JsonApiDotNetCore -c Release echo "APPVEYOR_REPO_TAG: $env:APPVEYOR_REPO_TAG" -echo "VERSION-SUFFIX: alpha1-$revision" + If($env:APPVEYOR_REPO_TAG -eq $true) { - echo "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts " - dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts + $revision = Get-Version-Suffix-From-Tag + echo "VERSION-SUFFIX: $revision" + echo "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=$revision" + dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=$revision } Else { + echo "VERSION-SUFFIX: alpha1-$revision" echo "RUNNING dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=alpha1-$revision" dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=alpha1-$revision -} +} \ No newline at end of file diff --git a/src/JsonApiDotNetCore/Formatters/JsonApiReader.cs b/src/JsonApiDotNetCore/Formatters/JsonApiReader.cs index 103c1b9ab5..274d14bc15 100644 --- a/src/JsonApiDotNetCore/Formatters/JsonApiReader.cs +++ b/src/JsonApiDotNetCore/Formatters/JsonApiReader.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using System.Text; using System.Threading.Tasks; using JsonApiDotNetCore.Internal; using JsonApiDotNetCore.Serialization; @@ -16,7 +15,7 @@ public class JsonApiReader : IJsonApiReader private readonly IJsonApiDeSerializer _deSerializer; private readonly IJsonApiContext _jsonApiContext; private readonly ILogger _logger; - + public JsonApiReader(IJsonApiDeSerializer deSerializer, IJsonApiContext jsonApiContext, ILoggerFactory loggerFactory) { @@ -37,11 +36,11 @@ public Task ReadAsync(InputFormatterContext context) try { var body = GetRequestBody(context.HttpContext.Request.Body); - var model = _jsonApiContext.IsRelationshipPath ? + var model = _jsonApiContext.IsRelationshipPath ? _deSerializer.DeserializeRelationship(body) : _deSerializer.Deserialize(body); - if(model == null) + if (model == null) _logger?.LogError("An error occurred while de-serializing the payload"); return InputFormatterResult.SuccessAsync(model); @@ -49,14 +48,13 @@ public Task ReadAsync(InputFormatterContext context) catch (JsonSerializationException ex) { _logger?.LogError(new EventId(), ex, "An error occurred while de-serializing the payload"); - context.HttpContext.Response.StatusCode = 422; + context.ModelState.AddModelError(context.ModelName, ex, context.Metadata); return InputFormatterResult.FailureAsync(); } - catch(JsonApiException jex) + catch (JsonApiException jex) { _logger?.LogError(new EventId(), jex, "An error occurred while de-serializing the payload"); - context.HttpContext.Response.StatusCode = jex.GetStatusCode(); - context.HttpContext.Response.Body = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(jex.GetError()))); + context.ModelState.AddModelError(context.ModelName, jex, context.Metadata); return InputFormatterResult.FailureAsync(); } } diff --git a/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj b/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj index 55775d73f5..f512d3505c 100755 --- a/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj +++ b/src/JsonApiDotNetCore/JsonApiDotNetCore.csproj @@ -1,6 +1,6 @@  - 2.1.0 + 2.1.1 netstandard1.6 JsonApiDotNetCore JsonApiDotNetCore