Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning Error to clients #156

Open
coutoluizf opened this issue Jul 23, 2020 · 1 comment
Open

Returning Error to clients #156

coutoluizf opened this issue Jul 23, 2020 · 1 comment

Comments

@coutoluizf
Copy link

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

@dupersec
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants