SH.APIProblemDetails
1.0.0
dotnet add package SH.APIProblemDetails --version 1.0.0
NuGet\Install-Package SH.APIProblemDetails -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SH.APIProblemDetails" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SH.APIProblemDetails" Version="1.0.0" />
<PackageReference Include="SH.APIProblemDetails" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SH.APIProblemDetails --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SH.APIProblemDetails, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SH.APIProblemDetails@1.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SH.APIProblemDetails&version=1.0.0
#tool nuget:?package=SH.APIProblemDetails&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SH.APIProblemDetails
介绍
在webapi中使用ProblemDetails来返回错误信息的统一格式化 ,实现 9475 标准协议 的快速集成
使用方法
请先安装 NuGet 包
dotnet add package SH.APIProblemDetails
配置
服务注册 后 及已经配置 自定义 ProblemDetails 集成,因为使用异常情况下处理,所以需要全局异常开启
builder.Services.AddProblemDetailsExceptionHandler();
...
var app = builder.Build();
app.UseExceptionHandler();
代码示例
[HttpGet("problemresult")]
public async Task<IResult> problemresult()
{
return Results.Problem(new ProblemDetails
{
Title = "我的测试",
Detail = "测试是否好事----------",
Type = "自定义类型",
});
}
[HttpGet("problemresult2")]
public async Task<IResult> problemresult2()
{
throw new ProblemDetailsException("异常测试", "我的错误原因!");
}
结果
{
"type": "Bad Request",
"title": "异常测试",
"status": 400,
"detail": "我的错误原因!",
"instance": "GET /api/Test/problemresult2",
"traceId": "00-3dac82cc8cff67ee0359de2277d822c6-39cd5d1071080f64-00",
"requestId": "0HNBPOQAQ1S81:00000005",
"spanId": "39cd5d1071080f64"
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- Microsoft.AspNetCore.Diagnostics (>= 2.3.0)
- Microsoft.AspNetCore.Diagnostics.Abstractions (>= 2.3.0)
- Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore (>= 9.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.0 | 117 | 4/12/2025 |