I'm making a call to an ODATA API, and the results of the JSON are changing after the promise is resolved.
Code block:
return client
.get(apiQueryString, AadHttpClient.configurations.v1)
.then((response: HttpClientResponse) => {
if (response.ok) {
return response.json();
}
else {
console.warn(response);
return;
}
})
.then((json: { value: INewBusinessProps[] }) =>{
return json.value;
})
If I throw in a console.log(response.json());
after the if (response.ok)
line, I get the data back correctly:
{first_name: "Fake", last_name: "User", user_type: "billing"}
{first_name: "Fake", last_name: "User", user_type: "originating"}
{first_name: "Fake", last_name: "User", user_type: "responsible"}
However, when I add console.log(json.value)
after the line .then((json: { value: INewBusinessProps[] }) =>{
, I get:
{first_name: "Fake", last_name: "User", user_type: "originating"}
{first_name: "Fake", last_name: "User", user_type: "originating"}
{first_name: "Fake", last_name: "User", user_type: "originating"}
(note the user_type)
Running from a browser or fiddler gives me the correct results; it's only after the then
that the data gets messed up.
I also thought it might be the type INewBusinessProps[]
that was the problem, so I changed it to any[]
and it still did not work.