I am trying to make an ajax request using window.fetch()
to an AWS lambda function of mine.
I followed the AWS Lambda guide on setting up CORS (and redeployed).
I followed the MDN documentation on adding headers to window.fetch()
to pass in my API key.
My code looks like this:
let myHeaders = new Headers();
myHeaders.append('x-api-key', lambda_key);
fetch('https://comically_long_aws_url.com/blah', {
headers: myHeaders,
})
.then((res)=>{
console.log('success,', res)
})
.catch((err)=>{
console.log('err', err);
});
If I look at the network tab, I see that both the OPTIONS and GET request were successful. Indeed, the GET returned the expected information:
Successful OPTIONS request:
Successful GET request:
Expected data in GET request response body:
Unexpected errors displaying in console:
Why is the window.fetch().catch()
error handler being invoked? Why is there a console error when the network call appears to be successful?