< Summary

Information
Class: LGDXRobotCloud.API.Exceptions.LgdxValidation400Expection
Assembly: LGDXRobotCloud.API
File(s): /builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Exceptions/LgdxValidation400Expection.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 14
Coverable lines: 14
Total lines: 23
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

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

File(s)

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

#LineLine coverage
 1using Microsoft.AspNetCore.Mvc.Infrastructure;
 2using Microsoft.AspNetCore.Mvc.ModelBinding;
 3
 4namespace LGDXRobotCloud.API.Exceptions;
 5
 06public class LgdxValidation400Expection(string key, string message) : Exception(message), ILgdxExceptionBase
 7{
 08  public string Key { get; init; } = key;
 9
 10  public async Task HandleExceptionAsync(HttpContext context)
 011  {
 012    context.Response.ContentType = "application/json";
 013    context.Response.StatusCode = StatusCodes.Status400BadRequest;
 014    ModelStateDictionary modelState = new();
 015    modelState.AddModelError(Key, Message);
 016    var problemDetailsFactory = context.RequestServices.GetRequiredService<ProblemDetailsFactory>();
 017    var response = problemDetailsFactory.CreateValidationProblemDetails(
 018      context,
 019      modelState
 020    );
 021    await context.Response.WriteAsJsonAsync(response);
 022  }
 23}