AxiosError问题

来源:6-4 错误信息增强 - 创建 AxiosError 类

慕用3095910

2019-12-12

export class AxiosError extends Error {
isAxiosError: boolean
config: AxiosRequestConfig
code?: string | null
request?: any
response?: AxiosResponse
constructor(
message: string,
config: AxiosRequestConfig,
code?: string | null,
request?: any,
response?: AxiosResponse
) {
super(message)

this.config = config
this.code = code
this.request = request
this.response = response
this.isAxiosError = true
Object.setPrototypeOf(this, AxiosError.prototype)

}
}

老师,想问super(message)为啥是message,而不是其他的

写回答

1回答

ustbhuangyi

2019-12-12

因为 Error 类的构造函数参数是 messge,String 类型的

0
2
ustbhuangyi
回复
慕用3095910
是啊,我们封装的 AxiosError 类,可以扩展任意参数。
2019-12-15
共2条回复

下一代前端开发语言 TypeScript从零重构axios

课程从零开始重构功能完整的JS库,是学习造轮子的不二之选!

2629 学习 · 877 问题

查看课程