Skip to content

Commit f2db2b0

Browse files
author
Bart Koelman
committed
Renamed RelationshipEntry to RelationshipObject, Error to ErrorObject
1 parent dbc67d4 commit f2db2b0

File tree

121 files changed

+564
-565
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+564
-565
lines changed

src/JsonApiDotNetCore/AtomicOperations/LocalIdTracker.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private void AssertIsNotDeclared(string localId)
3232
{
3333
if (_idsTracked.ContainsKey(localId))
3434
{
35-
throw new JsonApiException(new Error(HttpStatusCode.BadRequest)
35+
throw new JsonApiException(new ErrorObject(HttpStatusCode.BadRequest)
3636
{
3737
Title = "Another local ID with the same name is already defined at this point.",
3838
Detail = $"Another local ID with name '{localId}' is already defined at this point."
@@ -75,7 +75,7 @@ public string GetValue(string localId, string resourceType)
7575

7676
if (item.ServerId == null)
7777
{
78-
throw new JsonApiException(new Error(HttpStatusCode.BadRequest)
78+
throw new JsonApiException(new ErrorObject(HttpStatusCode.BadRequest)
7979
{
8080
Title = "Local ID cannot be both defined and used within the same operation.",
8181
Detail = $"Local ID '{localId}' cannot be both defined and used within the same operation."
@@ -89,7 +89,7 @@ private void AssertIsDeclared(string localId)
8989
{
9090
if (!_idsTracked.ContainsKey(localId))
9191
{
92-
throw new JsonApiException(new Error(HttpStatusCode.BadRequest)
92+
throw new JsonApiException(new ErrorObject(HttpStatusCode.BadRequest)
9393
{
9494
Title = "Server-generated value for local ID is not available at this point.",
9595
Detail = $"Server-generated value for local ID '{localId}' is not available at this point."
@@ -101,7 +101,7 @@ private static void AssertSameResourceType(string currentType, string declaredTy
101101
{
102102
if (declaredType != currentType)
103103
{
104-
throw new JsonApiException(new Error(HttpStatusCode.BadRequest)
104+
throw new JsonApiException(new ErrorObject(HttpStatusCode.BadRequest)
105105
{
106106
Title = "Type mismatch in local ID usage.",
107107
Detail = $"Local ID '{localId}' belongs to resource type '{declaredType}' instead of '{currentType}'."

src/JsonApiDotNetCore/AtomicOperations/LocalIdValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void Validate(IEnumerable<OperationContainer> operations)
4545
}
4646
catch (JsonApiException exception)
4747
{
48-
foreach (Error error in exception.Errors)
48+
foreach (ErrorObject error in exception.Errors)
4949
{
5050
error.Source.Pointer = $"/atomic:operations[{operationIndex}]{error.Source.Pointer}";
5151
}

src/JsonApiDotNetCore/AtomicOperations/OperationsProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public virtual async Task<IList<OperationContainer>> ProcessAsync(IList<Operatio
7777
}
7878
catch (JsonApiException exception)
7979
{
80-
foreach (Error error in exception.Errors)
80+
foreach (ErrorObject error in exception.Errors)
8181
{
8282
error.Source.Pointer = $"/atomic:operations[{results.Count}]{error.Source.Pointer}";
8383
}
@@ -88,7 +88,7 @@ public virtual async Task<IList<OperationContainer>> ProcessAsync(IList<Operatio
8888
catch (Exception exception)
8989
#pragma warning restore AV1210 // Catch a specific exception instead of Exception, SystemException or ApplicationException
9090
{
91-
throw new JsonApiException(new Error(HttpStatusCode.InternalServerError)
91+
throw new JsonApiException(new ErrorObject(HttpStatusCode.InternalServerError)
9292
{
9393
Title = "An unhandled error occurred while processing an operation in this request.",
9494
Detail = exception.Message,

src/JsonApiDotNetCore/Controllers/CoreJsonApiController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ namespace JsonApiDotNetCore.Controllers
99
/// </summary>
1010
public abstract class CoreJsonApiController : ControllerBase
1111
{
12-
protected IActionResult Error(Error error)
12+
protected IActionResult Error(ErrorObject error)
1313
{
1414
ArgumentGuard.NotNull(error, nameof(error));
1515

1616
return Error(error.AsEnumerable());
1717
}
1818

19-
protected IActionResult Error(IEnumerable<Error> errors)
19+
protected IActionResult Error(IEnumerable<ErrorObject> errors)
2020
{
2121
ArgumentGuard.NotNull(errors, nameof(errors));
2222

src/JsonApiDotNetCore/Errors/CannotClearRequiredRelationshipException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace JsonApiDotNetCore.Errors
1111
public sealed class CannotClearRequiredRelationshipException : JsonApiException
1212
{
1313
public CannotClearRequiredRelationshipException(string relationshipName, string resourceId, string resourceType)
14-
: base(new Error(HttpStatusCode.BadRequest)
14+
: base(new ErrorObject(HttpStatusCode.BadRequest)
1515
{
1616
Title = "Failed to clear a required relationship.",
1717
Detail = $"The relationship '{relationshipName}' of resource type '{resourceType}' " +

src/JsonApiDotNetCore/Errors/InvalidModelStateException.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,20 @@ private static void AddValidationErrors(ModelStateEntry entry, string propertyNa
5454
}
5555
}
5656

57-
private static IEnumerable<Error> FromModelStateViolations(IEnumerable<ModelStateViolation> violations, bool includeExceptionStackTraceInErrors,
57+
private static IEnumerable<ErrorObject> FromModelStateViolations(IEnumerable<ModelStateViolation> violations, bool includeExceptionStackTraceInErrors,
5858
JsonNamingPolicy namingPolicy)
5959
{
6060
ArgumentGuard.NotNull(violations, nameof(violations));
6161

6262
return violations.SelectMany(violation => FromModelStateViolation(violation, includeExceptionStackTraceInErrors, namingPolicy));
6363
}
6464

65-
private static IEnumerable<Error> FromModelStateViolation(ModelStateViolation violation, bool includeExceptionStackTraceInErrors,
65+
private static IEnumerable<ErrorObject> FromModelStateViolation(ModelStateViolation violation, bool includeExceptionStackTraceInErrors,
6666
JsonNamingPolicy namingPolicy)
6767
{
6868
if (violation.Error.Exception is JsonApiException jsonApiException)
6969
{
70-
foreach (Error error in jsonApiException.Errors)
70+
foreach (ErrorObject error in jsonApiException.Errors)
7171
{
7272
yield return error;
7373
}
@@ -100,9 +100,9 @@ private static string GetDisplayNameForProperty(string propertyName, Type resour
100100
return propertyName;
101101
}
102102

103-
private static Error FromModelError(ModelError modelError, string attributePath, bool includeExceptionStackTraceInErrors)
103+
private static ErrorObject FromModelError(ModelError modelError, string attributePath, bool includeExceptionStackTraceInErrors)
104104
{
105-
var error = new Error(HttpStatusCode.UnprocessableEntity)
105+
var error = new ErrorObject(HttpStatusCode.UnprocessableEntity)
106106
{
107107
Title = "Input validation failed.",
108108
Detail = modelError.ErrorMessage,

src/JsonApiDotNetCore/Errors/InvalidQueryException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace JsonApiDotNetCore.Errors
1313
public sealed class InvalidQueryException : JsonApiException
1414
{
1515
public InvalidQueryException(string reason, Exception exception)
16-
: base(new Error(HttpStatusCode.BadRequest)
16+
: base(new ErrorObject(HttpStatusCode.BadRequest)
1717
{
1818
Title = reason,
1919
Detail = exception?.Message

src/JsonApiDotNetCore/Errors/InvalidQueryStringParameterException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public sealed class InvalidQueryStringParameterException : JsonApiException
1414
public string QueryParameterName { get; }
1515

1616
public InvalidQueryStringParameterException(string queryParameterName, string genericMessage, string specificMessage, Exception innerException = null)
17-
: base(new Error(HttpStatusCode.BadRequest)
17+
: base(new ErrorObject(HttpStatusCode.BadRequest)
1818
{
1919
Title = genericMessage,
2020
Detail = specificMessage,

src/JsonApiDotNetCore/Errors/InvalidRequestBodyException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace JsonApiDotNetCore.Errors
1313
public sealed class InvalidRequestBodyException : JsonApiException
1414
{
1515
public InvalidRequestBodyException(string reason, string details, string requestBody, Exception innerException = null)
16-
: base(new Error(HttpStatusCode.UnprocessableEntity)
16+
: base(new ErrorObject(HttpStatusCode.UnprocessableEntity)
1717
{
1818
Title = reason != null ? $"Failed to deserialize request body: {reason}" : "Failed to deserialize request body.",
1919
Detail = FormatErrorDetail(details, requestBody, innerException)

src/JsonApiDotNetCore/Errors/JsonApiException.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ public class JsonApiException : Exception
2222
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
2323
};
2424

25-
public IReadOnlyList<Error> Errors { get; }
25+
public IReadOnlyList<ErrorObject> Errors { get; }
2626

2727
public override string Message => $"Errors = {JsonSerializer.Serialize(Errors, SerializerOptions)}";
2828

29-
public JsonApiException(Error error, Exception innerException = null)
29+
public JsonApiException(ErrorObject error, Exception innerException = null)
3030
: base(null, innerException)
3131
{
3232
ArgumentGuard.NotNull(error, nameof(error));
3333

3434
Errors = error.AsArray();
3535
}
3636

37-
public JsonApiException(IEnumerable<Error> errors, Exception innerException = null)
37+
public JsonApiException(IEnumerable<ErrorObject> errors, Exception innerException = null)
3838
: base(null, innerException)
3939
{
40-
List<Error> errorList = errors?.ToList();
40+
List<ErrorObject> errorList = errors?.ToList();
4141
ArgumentGuard.NotNullNorEmpty(errorList, nameof(errors));
4242

4343
Errors = errorList;

src/JsonApiDotNetCore/Errors/MissingTransactionSupportException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace JsonApiDotNetCore.Errors
1111
public sealed class MissingTransactionSupportException : JsonApiException
1212
{
1313
public MissingTransactionSupportException(string resourceType)
14-
: base(new Error(HttpStatusCode.UnprocessableEntity)
14+
: base(new ErrorObject(HttpStatusCode.UnprocessableEntity)
1515
{
1616
Title = "Unsupported resource type in atomic:operations request.",
1717
Detail = $"Operations on resources of type '{resourceType}' cannot be used because transaction support is unavailable."

src/JsonApiDotNetCore/Errors/NonParticipatingTransactionException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace JsonApiDotNetCore.Errors
1111
public sealed class NonParticipatingTransactionException : JsonApiException
1212
{
1313
public NonParticipatingTransactionException()
14-
: base(new Error(HttpStatusCode.UnprocessableEntity)
14+
: base(new ErrorObject(HttpStatusCode.UnprocessableEntity)
1515
{
1616
Title = "Unsupported combination of resource types in atomic:operations request.",
1717
Detail = "All operations need to participate in a single shared transaction, which is not the case for this request."

src/JsonApiDotNetCore/Errors/RelationshipNotFoundException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace JsonApiDotNetCore.Errors
1111
public sealed class RelationshipNotFoundException : JsonApiException
1212
{
1313
public RelationshipNotFoundException(string relationshipName, string resourceType)
14-
: base(new Error(HttpStatusCode.NotFound)
14+
: base(new ErrorObject(HttpStatusCode.NotFound)
1515
{
1616
Title = "The requested relationship does not exist.",
1717
Detail = $"Resource of type '{resourceType}' does not contain a relationship named '{relationshipName}'."

src/JsonApiDotNetCore/Errors/RequestMethodNotAllowedException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public sealed class RequestMethodNotAllowedException : JsonApiException
1414
public HttpMethod Method { get; }
1515

1616
public RequestMethodNotAllowedException(HttpMethod method)
17-
: base(new Error(HttpStatusCode.MethodNotAllowed)
17+
: base(new ErrorObject(HttpStatusCode.MethodNotAllowed)
1818
{
1919
Title = "The request method is not allowed.",
2020
Detail = $"Endpoint does not support {method} requests."

src/JsonApiDotNetCore/Errors/ResourceAlreadyExistsException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace JsonApiDotNetCore.Errors
1111
public sealed class ResourceAlreadyExistsException : JsonApiException
1212
{
1313
public ResourceAlreadyExistsException(string resourceId, string resourceType)
14-
: base(new Error(HttpStatusCode.Conflict)
14+
: base(new ErrorObject(HttpStatusCode.Conflict)
1515
{
1616
Title = "Another resource with the specified ID already exists.",
1717
Detail = $"Another resource of type '{resourceType}' with ID '{resourceId}' already exists."

src/JsonApiDotNetCore/Errors/ResourceIdInCreateResourceNotAllowedException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace JsonApiDotNetCore.Errors
1111
public sealed class ResourceIdInCreateResourceNotAllowedException : JsonApiException
1212
{
1313
public ResourceIdInCreateResourceNotAllowedException(int? atomicOperationIndex = null)
14-
: base(new Error(HttpStatusCode.Forbidden)
14+
: base(new ErrorObject(HttpStatusCode.Forbidden)
1515
{
1616
Title = atomicOperationIndex == null
1717
? "Specifying the resource ID in POST requests is not allowed."

src/JsonApiDotNetCore/Errors/ResourceIdMismatchException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace JsonApiDotNetCore.Errors
1111
public sealed class ResourceIdMismatchException : JsonApiException
1212
{
1313
public ResourceIdMismatchException(string bodyId, string endpointId, string requestPath)
14-
: base(new Error(HttpStatusCode.Conflict)
14+
: base(new ErrorObject(HttpStatusCode.Conflict)
1515
{
1616
Title = "Resource ID mismatch between request body and endpoint URL.",
1717
Detail = $"Expected resource ID '{endpointId}' in PATCH request body at endpoint '{requestPath}', instead of '{bodyId}'."

src/JsonApiDotNetCore/Errors/ResourceNotFoundException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace JsonApiDotNetCore.Errors
1111
public sealed class ResourceNotFoundException : JsonApiException
1212
{
1313
public ResourceNotFoundException(string resourceId, string resourceType)
14-
: base(new Error(HttpStatusCode.NotFound)
14+
: base(new ErrorObject(HttpStatusCode.NotFound)
1515
{
1616
Title = "The requested resource does not exist.",
1717
Detail = $"Resource of type '{resourceType}' with ID '{resourceId}' does not exist."

src/JsonApiDotNetCore/Errors/ResourceTypeMismatchException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace JsonApiDotNetCore.Errors
1313
public sealed class ResourceTypeMismatchException : JsonApiException
1414
{
1515
public ResourceTypeMismatchException(HttpMethod method, string requestPath, ResourceContext expected, ResourceContext actual)
16-
: base(new Error(HttpStatusCode.Conflict)
16+
: base(new ErrorObject(HttpStatusCode.Conflict)
1717
{
1818
Title = "Resource type mismatch between request body and endpoint URL.",
1919
Detail = $"Expected resource of type '{expected.PublicName}' in {method} request body at endpoint " +

src/JsonApiDotNetCore/Errors/ResourcesInRelationshipsNotFoundException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public ResourcesInRelationshipsNotFoundException(IEnumerable<MissingResourceInRe
1717
{
1818
}
1919

20-
private static Error CreateError(MissingResourceInRelationship missingResourceInRelationship)
20+
private static ErrorObject CreateError(MissingResourceInRelationship missingResourceInRelationship)
2121
{
2222
return new(HttpStatusCode.NotFound)
2323
{

src/JsonApiDotNetCore/Errors/ToManyRelationshipRequiredException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace JsonApiDotNetCore.Errors
1111
public sealed class ToManyRelationshipRequiredException : JsonApiException
1212
{
1313
public ToManyRelationshipRequiredException(string relationshipName)
14-
: base(new Error(HttpStatusCode.Forbidden)
14+
: base(new ErrorObject(HttpStatusCode.Forbidden)
1515
{
1616
Title = "Only to-many relationships can be updated through this endpoint.",
1717
Detail = $"Relationship '{relationshipName}' must be a to-many relationship."

src/JsonApiDotNetCore/Errors/UnsuccessfulActionResultException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace JsonApiDotNetCore.Errors
1212
public sealed class UnsuccessfulActionResultException : JsonApiException
1313
{
1414
public UnsuccessfulActionResultException(HttpStatusCode status)
15-
: base(new Error(status)
15+
: base(new ErrorObject(status)
1616
{
1717
Title = status.ToString()
1818
})
@@ -24,13 +24,13 @@ public UnsuccessfulActionResultException(ProblemDetails problemDetails)
2424
{
2525
}
2626

27-
private static Error ToError(ProblemDetails problemDetails)
27+
private static ErrorObject ToError(ProblemDetails problemDetails)
2828
{
2929
ArgumentGuard.NotNull(problemDetails, nameof(problemDetails));
3030

3131
HttpStatusCode status = problemDetails.Status != null ? (HttpStatusCode)problemDetails.Status.Value : HttpStatusCode.InternalServerError;
3232

33-
var error = new Error(status)
33+
var error = new ErrorObject(status)
3434
{
3535
Title = problemDetails.Title,
3636
Detail = problemDetails.Detail

src/JsonApiDotNetCore/Middleware/ExceptionHandler.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,25 @@ protected virtual ErrorDocument CreateErrorDocument(Exception exception)
7373
{
7474
ArgumentGuard.NotNull(exception, nameof(exception));
7575

76-
IReadOnlyList<Error> errors = exception is JsonApiException jsonApiException ? jsonApiException.Errors :
77-
exception is OperationCanceledException ? new Error((HttpStatusCode)499)
76+
IReadOnlyList<ErrorObject> errors = exception is JsonApiException jsonApiException ? jsonApiException.Errors :
77+
exception is OperationCanceledException ? new ErrorObject((HttpStatusCode)499)
7878
{
7979
Title = "Request execution was canceled."
80-
}.AsArray() : new Error(HttpStatusCode.InternalServerError)
80+
}.AsArray() : new ErrorObject(HttpStatusCode.InternalServerError)
8181
{
8282
Title = "An unhandled error occurred while processing this request.",
8383
Detail = exception.Message
8484
}.AsArray();
8585

86-
foreach (Error error in errors)
86+
foreach (ErrorObject error in errors)
8787
{
8888
ApplyOptions(error, exception);
8989
}
9090

9191
return new ErrorDocument(errors);
9292
}
9393

94-
private void ApplyOptions(Error error, Exception exception)
94+
private void ApplyOptions(ErrorObject error, Exception exception)
9595
{
9696
Exception resultException = exception is InvalidModelStateException ? null : exception;
9797

src/JsonApiDotNetCore/Middleware/IExceptionHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace JsonApiDotNetCore.Middleware
55
{
66
/// <summary>
7-
/// Central place to handle all exceptions. Log them and translate into Error response.
7+
/// Central place to handle all exceptions, such as log them and translate into error response.
88
/// </summary>
99
public interface IExceptionHandler
1010
{

0 commit comments

Comments
 (0)