lambda-api icon indicating copy to clipboard operation
lambda-api copied to clipboard

Returning Error to clients

Open coutoluizf opened this issue 5 years ago • 1 comments
trafficstars

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

coutoluizf avatar Jul 23 '20 14:07 coutoluizf

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

dupersec avatar Jul 24 '20 17:07 dupersec