Skip to content

Commit 135424e

Browse files
committed
fix: 错误提示
1 parent 2821622 commit 135424e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

MaiChartManager/ServerManager.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,13 @@ public static void StartApp(bool export, Action? onStart = null)
122122
.AllowAnyMethod()
123123
.AllowAnyHeader();
124124
}))
125-
.AddProblemDetails()
125+
.AddProblemDetails(options =>
126+
options.CustomizeProblemDetails = (context) =>
127+
{
128+
context.ProblemDetails.Title = context.Exception?.GetType()?.FullName ?? "未知错误";
129+
context.ProblemDetails.Detail = context.Exception?.Message ?? "未知错误";
130+
}
131+
)
126132
.AddControllers()
127133
.AddJsonOptions(options =>
128134
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()));
@@ -150,7 +156,10 @@ public static void StartApp(bool export, Action? onStart = null)
150156
if (onStart != null)
151157
app.Lifetime.ApplicationStarted.Register(onStart);
152158

153-
app.UseSwagger()
159+
app
160+
.UseExceptionHandler()
161+
.UseStatusCodePages()
162+
.UseSwagger()
154163
.UseSwaggerUI()
155164
.UseCors("qwq");
156165
if (export)

0 commit comments

Comments
 (0)