Skip to content

Commit a8ec0a5

Browse files
committed
API error response
400, 404 standard error response format added (similar to ASP..CORE model validation result)
1 parent 95a9f4c commit a8ec0a5

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Net;
5+
6+
namespace Supermarket.ApiResponse
7+
{
8+
public class BadRequestResponse : ValidationProblemDetails
9+
{
10+
public Guid TraceId { get; set; }
11+
public BadRequestResponse(string error) : base(new Dictionary<string, string[]> { { "error", new[] { error } } })
12+
{
13+
TraceId = Guid.NewGuid();
14+
Title = HttpStatusCode.BadRequest.ToString();
15+
}
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Net;
5+
6+
namespace Supermarket.ApiResponse
7+
{
8+
public class NotFoundResponse : ValidationProblemDetails
9+
{
10+
public Guid TraceId { get; set; }
11+
public NotFoundResponse(string error) : base(new Dictionary<string, string[]> { { "error", new[] { error } } })
12+
{
13+
TraceId = Guid.NewGuid();
14+
Title = HttpStatusCode.NotFound.ToString();
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)