«

2022年6月8日 AntDesignPro文档Demo示例[后置拦截器]报错

时间:2022-6-8 14:10     作者:Mahalalel     分类: React


场景

使用AntDesignPro的文档,写Demo示例时,使用了文档中的后置拦截器,运行以后,报了以下错误:

Unhandled Rejection (TypeError): Failed to execute 'append' on 'Headers': Headers are immutable

authResponseInterceptors
./src/app.ts:38
  35 | };
  36 | 
  37 | const authResponseInterceptors = (response: Response, options: RequestOptionsInit) => {
> 38 |   response.headers.append('interceptors', 'yes yo');
  39 |   return response;
  40 | };
  41 | 
View compiled
(anonymous function)
./node_modules/umi-request/dist/index.esm.js:718
This screen is visible only in development. It will not appear if the app crashes in production.
Open your browser’s developer console to further inspect this error.  Click the 'X' or hit ESC to dismiss this message.

问题

Unhandled Rejection (TypeError): Failed to execute 'append' on 'Headers': Headers are immutable

上面的异常信息,给我们提示了错误的原因,原来,‘Headers’是不可变的,所以没有办法使用append()方法。

后置拦截器,不能修改Headers的内容。

所以,注释掉response.headers.append('interceptors', 'yes yo');该行代码,报错即可消失。

标签: AntDesignPro 拦截器