Skip to content

Commit b876fad

Browse files
committed
Merge branch 'dev'
2 parents 345c0b4 + 7288907 commit b876fad

11 files changed

Lines changed: 22 additions & 29 deletions

File tree

ARConsistency/ARConsistency.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<RepositoryUrl>https://github.com/yoldascevik/ARConsistency</RepositoryUrl>
88
<PackageProjectUrl>https://github.com/yoldascevik/ARConsistency</PackageProjectUrl>
99
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
10-
<Version>1.1</Version>
11-
<PackageVersion>1.1</PackageVersion>
10+
<Version>1.1.2</Version>
11+
<PackageVersion>1.1.2</PackageVersion>
1212
</PropertyGroup>
1313

1414
<ItemGroup>

ARConsistency/Configuration/ExceptionStatusCodeHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void RegisterStatusCodedExceptionBaseType<TException>(
1919
if (!(statusCodeExpression.Body is MemberExpression memberExpression))
2020
throw new ArgumentException("Unable to resolve StatusCode member in expression.");
2121

22-
var memberType = memberExpression.Member.MemberType;
22+
MemberTypes memberType = memberExpression.Member.MemberType;
2323
if (memberType != MemberTypes.Field && memberType != MemberTypes.Property)
2424
throw new ArgumentException("StatusCode expression can be only Property or Field member.");
2525

ARConsistency/ConsistencyMiddleware.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,11 @@ private async Task HandleRequestAsync(HttpContext context, string body)
108108
private async Task HandleExceptionAsync(HttpContext context, ApiException exception)
109109
{
110110
ConsistentApiResponse response = exception.As<IConsistentable>().GetConsistentApiResponse();
111-
112-
_logger.LogError(exception, null);
113111
_responseHelper.FormatResponseAccordingToOptions(ref response, exception.StatusCode);
114-
112+
_logger.LogError(exception, ResponseMessage.GetResponseMessageByStatusCode(response.StatusCode));
113+
115114
string serializedResponse = JsonHelper.ConvertResponseToJsonString(response, _options);
116-
await _responseHelper.WriteFormattedResponseToHttpContextAsync(context, exception.StatusCode,
117-
serializedResponse);
115+
await _responseHelper.WriteFormattedResponseToHttpContextAsync(context, exception.StatusCode, serializedResponse);
118116
}
119117
}
120118
}

ARConsistency/Helpers/JsonHelper.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace ARConsistency.Helpers
1010
{
1111
internal static class JsonHelper
1212
{
13-
internal static string ConvertToJsonString(object rawJSON)
14-
=> JsonConvert.SerializeObject(rawJSON);
13+
internal static string ConvertToJsonString(object rawJson)
14+
=> JsonConvert.SerializeObject(rawJson);
1515

1616
internal static string ConvertResponseToJsonString(ConsistentApiResponse response, ResponseOptions options)
1717
=> JsonConvert.SerializeObject(response, Formatting.Indented, new JsonSerializerSettings()
@@ -25,6 +25,5 @@ internal static string ConvertResponseToJsonString(ConsistentApiResponse respons
2525

2626
internal static ConsistentApiResponse GetConsistentApiResponseFromJsonToken(JToken jsonToken)
2727
=> new ConsistentApiResponse(jsonToken.ToObject<object>());
28-
2928
}
3029
}

ARConsistency/Helpers/ResponseMessage.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ namespace ARConsistency.Helpers
55
internal class ResponseMessage
66
{
77
internal const string Success = "Request successful.";
8-
internal const string NotFound = "Request not found. The specified uri does not exist.";
8+
internal const string NotFound = "Request not found. The specified uri or entity does not exist.";
99
internal const string BadRequest = "Request invalid.";
1010
internal const string MethodNotAllowed = "Request responded with 'Method Not Allowed'.";
1111
internal const string NotContent = "Request no content. The specified uri does not contain any content.";
1212
internal const string Exception = "Request responded with exceptions.";
13-
internal const string UnAuthorized = "Request denied. Unauthorized access.";
13+
internal const string UnAuthorized = "Access denied.";
1414
internal const string ValidationError = "Request responded with validation error(s). Please correct the specified validation errors and try again.";
15-
internal const string Unhandled = "Unhandled Exception occurred. Unable to process the request.";
15+
internal const string Unhandled = "An unhandled exception was thrown by the application.";
1616

17-
internal static string GetResponseMessageByStatusCode(int statusCode) =>
17+
internal static string GetResponseMessageByStatusCode(int? statusCode) =>
1818
statusCode switch
1919
{
2020
StatusCodes.Status200OK => ResponseMessage.Success,
@@ -24,7 +24,7 @@ internal static string GetResponseMessageByStatusCode(int statusCode) =>
2424
StatusCodes.Status404NotFound => ResponseMessage.NotFound,
2525
StatusCodes.Status405MethodNotAllowed => ResponseMessage.MethodNotAllowed,
2626
StatusCodes.Status500InternalServerError => ResponseMessage.Unhandled,
27-
_ => null
27+
_ => ResponseMessage.Unhandled
2828
};
2929
}
3030
}

ARConsistency/ResponseModels/Base/ArcObjectResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public abstract class ArcObjectResult : ActionResult
1111

1212
public override Task ExecuteResultAsync(ActionContext context)
1313
{
14-
IActionResultExecutor<ObjectResult> executor = context.HttpContext.RequestServices.GetRequiredService<IActionResultExecutor<ObjectResult>>();
14+
var executor = context.HttpContext.RequestServices.GetRequiredService<IActionResultExecutor<ObjectResult>>();
1515

1616
context.HttpContext.Response.StatusCode = StatusCode;
1717
return executor.ExecuteAsync(context, new ObjectResult(this));

ARConsistency/ResponseModels/Base/ConsistentApiResponse.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ public class ConsistentApiResponse
1212
public string Message { get; set; }
1313
public bool IsError => !string.IsNullOrEmpty(ExceptionMessage) || (ValidationErrors != null && ValidationErrors.Any());
1414
public string ExceptionMessage { get; set; }
15-
public string ExceptionDetails { get; set; }
15+
public string ExceptionDetails { get; set; }
1616
public IEnumerable<ValidationError> ValidationErrors { get; set; }
17-
17+
1818
[JsonProperty(NullValueHandling = NullValueHandling.Include)]
1919
public object Payload { get; set; }
2020

21-
public ConsistentApiResponse()
22-
{
23-
}
21+
public ConsistentApiResponse() { }
2422

2523
public ConsistentApiResponse(object payload)
2624
:this()

ARConsistency/ServiceExtensions.cs renamed to ARConsistency/ServiceCollectionExtension.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using ARConsistency.Configuration;
45
using ARConsistency.ContractResolver;
@@ -11,7 +12,7 @@
1112

1213
namespace ARConsistency
1314
{
14-
public static class ServiceExtensions
15+
public static class ServiceCollectionExtension
1516
{
1617
public static IMvcBuilder AddApiResponseConsistency(this IMvcBuilder builder,
1718
Action<ArcConfiguration> configurationBuilder)
@@ -42,8 +43,7 @@ public static IApplicationBuilder UseApiResponseConsistency(this IApplicationBui
4243
#region Private Helper Methods
4344
private static void Configure(IServiceCollection services, Action<ArcConfiguration> configurationBuilder)
4445
{
45-
ArcConfiguration configuration = new ArcConfiguration();
46-
46+
var configuration = new ArcConfiguration();
4747
configurationBuilder.Invoke(configuration);
4848
services.AddSingleton(configuration.ResponseOptions);
4949
services.AddSingleton(configuration.ExceptionStatusCodeHandler);
@@ -55,7 +55,7 @@ private static void SuppressBadRequestResponse(IServiceCollection services)
5555
{
5656
options.InvalidModelStateResponseFactory = context =>
5757
{
58-
var validationErrors = context.ModelState.Keys
58+
List<ValidationError> validationErrors = context.ModelState.Keys
5959
.SelectMany(key => context.ModelState[key].Errors.Select(x => new ValidationError(key, x.ErrorMessage)))
6060
.ToList();
6161

Test/TestApi/Startup.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using ARConsistency;
2-
using ARConsistency.Configuration;
32
using Microsoft.AspNetCore.Builder;
43
using Microsoft.AspNetCore.Hosting;
54
using Microsoft.Extensions.Configuration;

Test/WebApiTest/ActionTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Net;
44
using System.Net.Http;
55
using ARConsistency.ResponseModels.Base;
6-
using Microsoft.AspNetCore.Mvc.Infrastructure;
76
using Newtonsoft.Json;
87
using TestApi.Models;
98
using WebApiTest.Helpers;

0 commit comments

Comments
 (0)