Skip to content

Commit

Permalink
Merge pull request #1 from VirtoCommerce/dev
Browse files Browse the repository at this point in the history
PT-12651: Return an HTTP status code of 409 (Conflict)  (VirtoCommerce#2675)
  • Loading branch information
gundarsv committed Jul 25, 2023
2 parents d525e07 + 3d40739 commit 6c8dd89
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace VirtoCommerce.Platform.Web.Middleware
Expand Down Expand Up @@ -37,7 +38,7 @@ public async Task Invoke(HttpContext context)
var shortMessage = ex.InnerException == null ? ex.Message : ex.InnerException.Message;
var message = !isDevelopment ? shortMessage : $@"An exception occurred while processing the request [{context.Request.Path}]: {ex}";
_logger.LogError(ex, message);
var httpStatusCode = HttpStatusCode.InternalServerError;
var httpStatusCode = ex is DbUpdateConcurrencyException ? HttpStatusCode.Conflict : HttpStatusCode.InternalServerError;
var json = JsonConvert.SerializeObject(new { message, stackTrace = isDevelopment ? ex.StackTrace : null });
context.Response.ContentType = "application/json";
context.Response.StatusCode = (int)httpStatusCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@
},
"errors": {
"5XX": "Internal Server Error",
"4XX": "Unauthorized"
"4XX": "Unauthorized",
"404": "Not Found",
"409": "Conflict"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,13 @@ angular.module('platformWebApp')
var result = "";
var statusString = response.status.toString();

if (statusString.startsWith('4')) {
if (statusString === '404') {
result = $translate.instant('platform.errors.404');
}
else if (statusString === '409') {
result = $translate.instant('platform.errors.409');
}
else if (statusString.startsWith('4')) {
result = $translate.instant('platform.errors.4XX');
}
else if (statusString.startsWith('5')) {
Expand Down

0 comments on commit 6c8dd89

Please sign in to comment.