< Summary

Information
Class: LGDXRobotCloud.API.Exceptions.LgdxIdentity400Expection
Assembly: LGDXRobotCloud.API
File(s): /builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Exceptions/LgdxValidationList400Expection.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 16
Coverable lines: 16
Total lines: 25
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
HandleExceptionAsync()0%620%

File(s)

/builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Exceptions/LgdxValidationList400Expection.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Identity;
 2using Microsoft.AspNetCore.Mvc.Infrastructure;
 3using Microsoft.AspNetCore.Mvc.ModelBinding;
 4
 5namespace LGDXRobotCloud.API.Exceptions;
 6
 07public class LgdxIdentity400Expection(IEnumerable<IdentityError> errors) : Exception(), ILgdxExceptionBase
 8{
 9  public async Task HandleExceptionAsync(HttpContext context)
 010  {
 011    context.Response.ContentType = "application/json";
 012    context.Response.StatusCode = StatusCodes.Status400BadRequest;
 013    ModelStateDictionary modelState = new();
 014    foreach (var error in errors)
 015    {
 016      modelState.AddModelError(error.Code, error.Description);
 017    }
 018    var problemDetailsFactory = context.RequestServices.GetRequiredService<ProblemDetailsFactory>();
 019    var response = problemDetailsFactory.CreateValidationProblemDetails(
 020      context,
 021      modelState
 022    );
 023    await context.Response.WriteAsJsonAsync(response);
 024  }
 25}