< Summary

Information
Class: LGDXRobotCloud.API.Exceptions.LgdxValidation400Expection
Assembly: LGDXRobotCloud.API
File(s): /builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Exceptions/LgdxValidation400Expection.cs
Line coverage
100%
Covered lines: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 23
Line coverage: 100%
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%11100%
get_Key()100%11100%
HandleExceptionAsync()100%11100%

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
 466public class LgdxValidation400Expection(string key, string message) : Exception(message), ILgdxExceptionBase
 7{
 478  public string Key { get; init; } = key;
 9
 10  public async Task HandleExceptionAsync(HttpContext context)
 111  {
 112    context.Response.ContentType = "application/json";
 113    context.Response.StatusCode = StatusCodes.Status400BadRequest;
 114    ModelStateDictionary modelState = new();
 115    modelState.AddModelError(Key, Message);
 116    var problemDetailsFactory = context.RequestServices.GetRequiredService<ProblemDetailsFactory>();
 117    var response = problemDetailsFactory.CreateValidationProblemDetails(
 118      context,
 119      modelState
 120    );
 121    await context.Response.WriteAsJsonAsync(response);
 122  }
 23}