lambda-api
lambda-api copied to clipboard
Returning Error to clients
Hey Jeremy,
First of all thanks for the amazing framework. I'm struggling here regarding returning error to clients, like 404 not found.
If i use the framework error engine this way: res.status(404).error('Not found')
Then in clients like Chrome we always get the bellow cors issue: has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled
And belive me i have all the cors stuff in the right place.
In the other hand if i use this way: res.status(404).json('Not found')
Then everthing is fine, i got a 404 in Chrome
I'm i doing something wrong ?
Thanks in advance, Luiz
Ran into this too, have to add cors headers to the errorHeaderWhitelist:
const api = lambdaApi({
errorHeaderWhitelist: [
'access-control-allow-origin',
'access-control-allow-methods',
'access-control-allow-headers',
],
});
Maybe this should be the default? Or at least in the docs somewhere