Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
86311d9
feat(*): interface segregation
jaredcnance Jun 12, 2017
f8a7ac2
Merge branch 'feat/cqrs' into unstable
jaredcnance Jun 12, 2017
54575d7
Merge branch 'unstable' into master
jaredcnance Jun 14, 2017
40ffa82
Merge pull request #133 from Research-Institute/master
jaredcnance Jun 14, 2017
60f7713
Merge pull request #134 from Research-Institute/master
jaredcnance Jun 14, 2017
46f2d07
feat(serialization): improve support for complex attrs
jaredcnance Jun 13, 2017
3de6d21
fix(typeHelper): handle complex types
jaredcnance Jun 23, 2017
deb57df
feat(services): complete interface segregation
jaredcnance Jun 25, 2017
fc7f702
chore(examples): move projects under examples directory
jaredcnance Jun 25, 2017
504dfa1
feat(reports): add reports example
jaredcnance Jun 25, 2017
18ae7c8
Merge branch 'feat/#125' into unstable
jaredcnance Jun 25, 2017
d804628
chore(#117): remove deprecated constructor
jaredcnance Jun 25, 2017
59fc512
feat(#129): optionally disable links
jaredcnance Jun 25, 2017
c131839
feat(#130): disable query params
jaredcnance Jun 27, 2017
c08fbe0
feat(#128): immutable attributes
jaredcnance Jun 28, 2017
ee0025f
feat(#139): handle empty strings in type helper
jaredcnance Jun 28, 2017
a894f69
feat(#138): improved exception handling
jaredcnance Jun 28, 2017
6ed2a4f
test(base-controller): add unit tests
jaredcnance Jul 2, 2017
e792b8e
Merge pull request #140 from Research-Institute/unstable
jaredcnance Jul 2, 2017
b46d299
add documentation
jaredcnance Jul 2, 2017
93b063e
add documentation
jaredcnance Jul 2, 2017
6e92a9f
fix(#126): implicitly add db context to context graph
jaredcnance Jul 2, 2017
ad8787e
fix(ctx-graph-builder): set link flags to prevent ordering issues
jaredcnance Jul 2, 2017
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(#138): improved exception handling
  • Loading branch information
jaredcnance committed Jun 28, 2017
commit a894f697a02016c1e79d3ae9f47c272725720e34
16 changes: 8 additions & 8 deletions src/JsonApiDotNetCore/Controllers/BaseJsonApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected BaseJsonApiController(

public virtual async Task<IActionResult> GetAsync()
{
if (_getAll == null) throw new JsonApiException(405, "Query requests are not supported");
if (_getAll == null) throw new JsonApiException(405, "Get requests are not supported");

var entities = await _getAll.GetAsync();

Expand All @@ -86,7 +86,7 @@ public virtual async Task<IActionResult> GetAsync()

public virtual async Task<IActionResult> GetAsync(TId id)
{
if (_getById == null) throw new JsonApiException(405, "Query requests are not supported");
if (_getById == null) throw new JsonApiException(405, "Get by Id requests are not supported");

var entity = await _getById.GetAsync(id);

Expand All @@ -98,7 +98,7 @@ public virtual async Task<IActionResult> GetAsync(TId id)

public virtual async Task<IActionResult> GetRelationshipsAsync(TId id, string relationshipName)
{
if (_getRelationships == null) throw new JsonApiException(405, "Query requests are not supported");
if (_getRelationships == null) throw new JsonApiException(405, "Get Relationships requests are not supported");

var relationship = await _getRelationships.GetRelationshipsAsync(id, relationshipName);
if (relationship == null)
Expand All @@ -109,7 +109,7 @@ public virtual async Task<IActionResult> GetRelationshipsAsync(TId id, string re

public virtual async Task<IActionResult> GetRelationshipAsync(TId id, string relationshipName)
{
if (_getRelationship == null) throw new JsonApiException(405, "Query requests are not supported");
if (_getRelationship == null) throw new JsonApiException(405, "Get Relationship requests are not supported");

var relationship = await _getRelationship.GetRelationshipAsync(id, relationshipName);

Expand All @@ -118,7 +118,7 @@ public virtual async Task<IActionResult> GetRelationshipAsync(TId id, string rel

public virtual async Task<IActionResult> PostAsync([FromBody] T entity)
{
if (_create == null) throw new JsonApiException(405, "Command requests are not supported");
if (_create == null) throw new JsonApiException(405, "Post requests are not supported");

if (entity == null)
return UnprocessableEntity();
Expand All @@ -133,7 +133,7 @@ public virtual async Task<IActionResult> PostAsync([FromBody] T entity)

public virtual async Task<IActionResult> PatchAsync(TId id, [FromBody] T entity)
{
if (_update == null) throw new JsonApiException(405, "Command requests are not supported");
if (_update == null) throw new JsonApiException(405, "Patch requests are not supported");

if (entity == null)
return UnprocessableEntity();
Expand All @@ -148,7 +148,7 @@ public virtual async Task<IActionResult> PatchAsync(TId id, [FromBody] T entity)

public virtual async Task<IActionResult> PatchRelationshipsAsync(TId id, string relationshipName, [FromBody] List<DocumentData> relationships)
{
if (_updateRelationships == null) throw new JsonApiException(405, "Command requests are not supported");
if (_updateRelationships == null) throw new JsonApiException(405, "Relationship Patch requests are not supported");

await _updateRelationships.UpdateRelationshipsAsync(id, relationshipName, relationships);

Expand All @@ -157,7 +157,7 @@ public virtual async Task<IActionResult> PatchRelationshipsAsync(TId id, string

public virtual async Task<IActionResult> DeleteAsync(TId id)
{
if (_delete == null) throw new JsonApiException(405, "Command requests are not supported");
if (_delete == null) throw new JsonApiException(405, "Delete requests are not supported");

var wasDeleted = await _delete.DeleteAsync(id);

Expand Down
4 changes: 4 additions & 0 deletions src/JsonApiDotNetCore/Internal/JsonApiException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public JsonApiException(int statusCode, string message, string detail)
: base(message)
=> _errors.Add(new Error(statusCode, message, detail));

public JsonApiException(int statusCode, string message, Exception innerException)
: base(message, innerException)
=> _errors.Add(new Error(statusCode, message, innerException.Message));

public ErrorCollection GetError() => _errors;

public int GetStatusCode()
Expand Down
6 changes: 3 additions & 3 deletions src/JsonApiDotNetCore/Serialization/JsonApiDeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public object Deserialize(string requestBody)
}
catch (Exception e)
{
throw new JsonApiException(400, "Failed to deserialize request body", e.Message);
throw new JsonApiException(400, "Failed to deserialize request body", e);
}
}

Expand All @@ -54,7 +54,7 @@ public object DeserializeRelationship(string requestBody)
}
catch (Exception e)
{
throw new JsonApiException(400, "Failed to deserialize request body", e.Message);
throw new JsonApiException(400, "Failed to deserialize request body", e);
}
}

Expand All @@ -75,7 +75,7 @@ public List<TEntity> DeserializeList<TEntity>(string requestBody)
}
catch (Exception e)
{
throw new JsonApiException(400, "Failed to deserialize request body", e.Message);
throw new JsonApiException(400, "Failed to deserialize request body", e);
}
}

Expand Down