代码改变世界

(四)React+.Net+Typescript全栈(错误处理) - 指南

2025-10-10 22:58  tlnshuju  阅读(1)  评论(0)    收藏  举报


项目地址

  • 教程作者:
  • 教程地址:
  • 代码仓库地址:
  • 所用到的框架和插件:
dbt
airflow

一、错误处理

1.1 普通弹窗处理

1. baseapi

  • baseApi.ts里通过对response的判断,来决定是否
  • 通过switch判断,普通错误使用toast组件,显示在页面的右下角
const customBaseQuery = fetchBaseQuery({

baseUrl: 'https://localhost:5001/api'
});
type ErrorResponse = | string | {
title: string
} | {
errors: string[]
};
const sleep = () =>
new Promise(resolve =>
setTimeout(resolve, 1000));
export const baseQueryWithErrorHandling = async (args: string | FetchArgs, api: BaseQueryApi,
extraOptions: object) =>
{

api.dispatch(startLoading());
await sleep();
const result = await customBaseQuery(args, api, extraOptions);
api.dispatch(stopLoading());
if (result.error) {

console