From f4a2597ac4534287f8fd9a1e0c0da95cb62637bb Mon Sep 17 00:00:00 2001 From: Lukash88 Date: Fri, 29 Dec 2023 23:29:49 +0100 Subject: [PATCH] refactor(webbackend): Apply requested changes in PR --- .../Extensions/ApplicationServices.cs | 1 - .../Services/Middleware/ErrorHandlingMiddleware.cs | 2 +- .../GetProblemDetailsByExceptionFactory.cs | 14 ++++---------- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/binder-web-backend/Binder.Application/Extensions/ApplicationServices.cs b/binder-web-backend/Binder.Application/Extensions/ApplicationServices.cs index 5fabd47..6ce6b72 100644 --- a/binder-web-backend/Binder.Application/Extensions/ApplicationServices.cs +++ b/binder-web-backend/Binder.Application/Extensions/ApplicationServices.cs @@ -1,6 +1,5 @@ using Binder.Application.Models.Interfaces; using Binder.Application.Services; -using Binder.Application.Services.Middleware; using Microsoft.Extensions.DependencyInjection; namespace Binder.Application.Extensions diff --git a/binder-web-backend/Binder.Application/Services/Middleware/ErrorHandlingMiddleware.cs b/binder-web-backend/Binder.Application/Services/Middleware/ErrorHandlingMiddleware.cs index 0ca2ebd..ef02ea4 100644 --- a/binder-web-backend/Binder.Application/Services/Middleware/ErrorHandlingMiddleware.cs +++ b/binder-web-backend/Binder.Application/Services/Middleware/ErrorHandlingMiddleware.cs @@ -22,7 +22,7 @@ public async Task InvokeAsync(HttpContext context) } catch (Exception e) { - ProblemDetails? problemDetails = GetProblemDetailsByExceptionFactory.HandleException(e); + ProblemDetails problemDetails = GetProblemDetailsByExceptionFactory.GetProblemDetails(e); context.Response.StatusCode = (int)problemDetails.Status; context.Response.ContentType = problemJsonType; diff --git a/binder-web-backend/Binder.Application/Services/Middleware/GetProblemDetailsByExceptionFactory.cs b/binder-web-backend/Binder.Application/Services/Middleware/GetProblemDetailsByExceptionFactory.cs index 0ccf7c5..a6bc918 100644 --- a/binder-web-backend/Binder.Application/Services/Middleware/GetProblemDetailsByExceptionFactory.cs +++ b/binder-web-backend/Binder.Application/Services/Middleware/GetProblemDetailsByExceptionFactory.cs @@ -7,38 +7,32 @@ namespace Binder.Application.Services.Middleware { public static class GetProblemDetailsByExceptionFactory { - public static ProblemDetails HandleException(Exception exception) + public static ProblemDetails GetProblemDetails(Exception exception) { - ProblemDetails problemDetails; switch (exception) { case InvalidOperationException: - problemDetails = new ProblemDetails + return new ProblemDetails { Title = nameof(HttpStatusCode.BadRequest), Status = (int)HttpStatusCode.BadRequest, Detail = ExceptionConstants.InvalidOperationMessage, }; - break; case NotFoundException: - problemDetails = new ProblemDetails + return new ProblemDetails { Title = nameof(HttpStatusCode.NotFound), Status = (int)HttpStatusCode.NotFound, Detail = ExceptionConstants.ResourceNotFoundMessage }; - break; default: - problemDetails = new ProblemDetails + return new ProblemDetails { Title = nameof(HttpStatusCode.InternalServerError), Status = (int)HttpStatusCode.InternalServerError, Detail = ExceptionConstants.UnexpectedErrorMessage, }; - break; }; - - return problemDetails; } } } \ No newline at end of file