Skip to content

Commit

Permalink
improve the error responses returned from the microservices
Browse files Browse the repository at this point in the history
skills from the Logging and Monitoring in ASP.NET Core 6 course by Erik Dahl are used here [which i'm still watching at the moment]

make use of a nuget package called hellang.middleware.problemdetails to return a problemdetails object instead of the stack trace of the error when one occurs

this is a small prep for the logging spree i'm gonna go on later after i prep for centralized logging
  • Loading branch information
ShaylenReddy42 committed Sep 24, 2022
1 parent 8a95649 commit 7741813
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ The WebApi will be split into microservices that has its own databases using Dom
* Author: [Kevin Dockx](https://app.pluralsight.com/profile/author/kevin-dockx)
* [Cryptography in .NET 6](https://www.pluralsight.com/courses/dot-net-6-cryptography)
* Author: [Stephen Haunts](https://app.pluralsight.com/profile/author/stephen-haunts)
* [Logging and Monitoring in ASP.NET Core 6](https://www.pluralsight.com/courses/logging-monitoring-aspdotnet-core-6)
* Author: [Erik Dahl](https://app.pluralsight.com/profile/author/erik-dahl)
* [Sending Email in C# using FluentEmail](https://www.youtube.com/watch?v=qSeO9886nRM)
* Author: [IAmTimCorey](https://www.youtube.com/user/IAmTimCorey)
* [Microsoft Docs](https://docs.microsoft.com/en-us/)
Expand Down
9 changes: 8 additions & 1 deletion Services/SeelansTyres.Services.AddressService/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Hellang.Middleware.ProblemDetails;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore;
Expand All @@ -6,7 +7,6 @@
using SeelansTyres.Services.AddressService.Data;
using SeelansTyres.Services.AddressService.Services;
using System.Reflection;
using System.Text;

var builder = WebApplication.CreateBuilder(args);

Expand Down Expand Up @@ -69,8 +69,15 @@

builder.Services.AddHttpContextAccessor();

builder.Services.AddProblemDetails(configure =>
{
configure.IncludeExceptionDetails = (httpContext, exception) => false;
});

var app = builder.Build();

app.UseProblemDetails();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
<PackageReference Include="Hellang.Middleware.ProblemDetails" Version="6.5.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.8">
<PrivateAssets>all</PrivateAssets>
Expand Down
8 changes: 8 additions & 0 deletions Services/SeelansTyres.Services.OrderService/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Hellang.Middleware.ProblemDetails;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -72,8 +73,15 @@

builder.Services.AddHttpContextAccessor();

builder.Services.AddProblemDetails(configure =>
{
configure.IncludeExceptionDetails = (httpContext, exception) => false;
});

var app = builder.Build();

app.UseProblemDetails();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
<PackageReference Include="Hellang.Middleware.ProblemDetails" Version="6.5.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.8">
<PrivateAssets>all</PrivateAssets>
Expand Down
10 changes: 8 additions & 2 deletions Services/SeelansTyres.Services.TyresService/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Hellang.Middleware.ProblemDetails;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
using SeelansTyres.Services.TyresService.Authorization;
using SeelansTyres.Services.TyresService.Data;
using SeelansTyres.Services.TyresService.Services;
using System.Reflection;
using System.Text;

var builder = WebApplication.CreateBuilder(args);

Expand Down Expand Up @@ -67,8 +66,15 @@

builder.Services.AddHttpContextAccessor();

builder.Services.AddProblemDetails(configure =>
{
configure.IncludeExceptionDetails = (httpContext, exception) => false;
});

var app = builder.Build();

app.UseProblemDetails();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
<PackageReference Include="Hellang.Middleware.ProblemDetails" Version="6.5.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.8">
<PrivateAssets>all</PrivateAssets>
Expand Down

0 comments on commit 7741813

Please sign in to comment.