Skip to content

Commit

Permalink
Merge pull request #87 from joukevandermaas/merge-back-86
Browse files Browse the repository at this point in the history
Fix regression: `HttpError` not passed through
  • Loading branch information
Jouke van der Maas committed Jan 20, 2016
2 parents 4992163 + 6b4ebb2 commit 2b56812
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
## Version 1.4.1

- [**REGRESSION**] `HttpError` not passed through; Saule specific error is serialized instead.

## Version 1.4

- [**FEATURE**] Filtering of attributes through user queries
- You can specify the expression that will be executed for specific types, allowing
e.g. case-insensitive filtering, and much more.
- [**FEATURE**] Custom properties to specify the Id of a resource (using `WithId`)
- [**FEATURE**] New way to set up Saule: use the extension method `ConfigureJsonApi`
- [**FEATURE**] New way to set up Saule: use the extension method `ConfigureJsonApi`
instead of manually adding the `JsonApiMediaTypeFormatter`.
- [**FEATURE**] Better response code handling; Saule will now always send a 4xx or 5xx when an exception occurs
(requires the new setup)
Expand Down
6 changes: 4 additions & 2 deletions Saule/Http/PreprocessingDelegatingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ internal static PreprocessResult PreprocessRequest(
{
resource = (ApiResource)request.Properties[Constants.RequestPropertyName];
}
else
else if (!(content is HttpError))
{
content = new JsonApiException(ErrorType.Server, "You must add a [ReturnsResourceAttribute] to action methods.")
content = new JsonApiException(
ErrorType.Server,
"You must add a [ReturnsResourceAttribute] to action methods.")
{
HelpLink = "https://github.com/joukevandermaas/saule/wiki"
};
Expand Down
13 changes: 12 additions & 1 deletion Tests/Controllers/BrokenController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Web.Http;
using System.Linq;
using System.Web.Http;
using Saule.Http;
using Tests.Helpers;
using Tests.Models;

Expand All @@ -12,5 +14,14 @@ public Person GetPerson(string id)
{
return Get.Person(id);
}

[HttpGet]
[ReturnsResource(typeof(PersonResource))]
[Route("api/broken")]
[Authorize]
public IQueryable<Person> GetPeople()
{
return Get.People(20).AsQueryable();
}
}
}
19 changes: 18 additions & 1 deletion Tests/Integration/JsonApiMediaTypeFormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,24 @@ public async Task PassesThrough400Errors()
var client = server.GetClient();
var response = await client.GetAsync("does/not/exist");

Assert.Equal(response.StatusCode, HttpStatusCode.NotFound);
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
}
}

[Fact(DisplayName = "Passes through HttpError")]
public async Task PassesThroughHttpErrors()
{
using (var server = new NewSetupJsonApiServer())
{
var client = server.GetClient();
var response = await client.GetFullJsonResponseAsync("api/broken");

_output.WriteLine(response.Content.ToString());

var errorText = response.Content["errors"][0]["title"].Value<string>();

Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
Assert.Equal("Authorization has been denied for this request.", errorText);
}
}

Expand Down
4 changes: 3 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
version: 1.4.0.{build}
version: 1.4.1.{build}
configuration: Release
skip_tags: true
assembly_info:
patch: true
file: '**\AssemblyInfo.*'
Expand All @@ -18,6 +19,7 @@ deploy:
api_key:
secure: dtP6YFOY3quvyRlH0DYG/i4AbOegM/5oT8Q+IcpKMqKZgBiAmm+XRs2TN9+ju9oe
on:
appveyor_repo_tag: false
branch: /(master|release-v.+)/
- release: saule-v$(appveyor_build_version)
description: ''
Expand Down

0 comments on commit 2b56812

Please sign in to comment.