无法对从 MS Graph 接收到的用户对象使用 response.json()

Can't use response.json() on received user object from MS Graph

我正在尝试从 MS Graph 获取用户 API。

export const getUser = async (id) => {
    //Gives me the token
    const token = await getToken(["User.Read", "User.ReadWrite"])
    //Appends to headers
    const headers = getHeaders(token)
    
    const options = {
        method: "GET",
        headers: headers
    };
    return fetch(`https://graph.microsoft.com/v1.0/users/${id}`, options)
}

getUser("MYID").then(response => response.json()).then(response => {
    debugger
}).catch((error) => {
    debugger
})

通常我可以使用 .json() 来解决来自 MS Graph 的承诺,但此调用失败并出现以下错误:

Unexpected token < in JSON at position 0

如果我删除 .json(),我可以阅读回复,其中提供了以下内容:

response: Response
body: ReadableStream
bodyUsed: false
headers: Headers {}
ok: true
redirected: false
status: 200
statusText: "OK"
type: "basic"

考虑到 body 对象应该是 ReadableStream 类型,我的直觉告诉我,我实际上应该能够用 .json() 解决承诺,即 response.body.json()。但是,当我尝试这样做时,出现以下错误:

TypeError: response.body.json is not a function at http://localhost:3000/static/js/main.chunk.js:4679:40

我不太确定发生了什么,如果你们能给我一些关于正在发生的事情的见解,我自然会很高兴。当我想解析 readableStream 时,我所有其他图形“GET”调用都没有遇到问题。

我相信你得到的响应正文是 html 或 xml 这就是为什么 .json() 用于将数据解析为 json 的原因异常 意外令牌 < in JSON 在位置 0