-
Notifications
You must be signed in to change notification settings - Fork 116
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
Request to allow return of an object or string instead of response, assuming 200 #29
Comments
Another idea might be to re-write the callback function to something like this:
|
nice catch! indeed, I didn't read the whole AWS document to implement that, and I'm personally returning |
I’ve been reading up on this to try and figure out how to put together a PR suggestion. However, it is remarkably complex, even though it’s only replacing 1 line of code. I’m going to note it down here incase somebody in the future stumbles into this area. The ‘Netlify Functions’ product is actually ‘Netlify Lambda + Lambda functions, when left to their own devices, will return a However, Netlify have paired it up with (what looks like) API Gateway behind the scenes – or have rolled their own that mimics its behaviour somewhat. When you return a response object, complete with My original request was that the discovery of allowing Lambda functions to return just a promise is actually not relatable to the way Netlify Functions works. If you’re using Lambda without API Gateway proxying the request, you’ve always been able to return just a string, and it would be returned as a 200. There is no way to override the status code just using Lambda, without using API Gateway as a proxy. So the fact that it’s able to resolve a promise and return the value is irrelevant. So, having dug deep into this now, I have realised that my request is not a bug, but actually a feature request. My dream is that I can have a chain of functions that pass a promise all the way back up to the handler, which when resolved is the value of body. I have structured my functions using Middy as a ‘middleware’, and then organised everything into an MVC-style pattern. It’s not actually using a framework, but the structure mimics MVC. In this pattern, when a DynamoDB promise returns the contents of a file, I don’t want to declare the status code of the response at this point. These functions are shared, so it’s not the responsibility of a model function to set an HTTP status. My request is that I’d like to be able to return an object as the resolve of a promise, and that Netlify Lambda would assume that object is good to send on to the user. However, to mimic the behaviour of Lambda, this should also be valid if it’s not an object (a string), and it should also behave that way if it is returned outside of a promise. I think that in the most TL;DR way: Would it be okay to allow the return of an object, that’s converted into a JSON string and the content type set, or a string, and then allow it to return that with a 200? If you’d like to override it, or set headers, then you can just return that. I guess the test would be – if an object is returned and it has both a If I had more time I would write a shorter comment. |
no stalebot, this is a really good issue! @ThomasEdwards and @8eecf0d2 you folks have thought about this far more than i have. would happily take a PR for the intuitive behavior. |
Just tested out thomasedwards/netlify-lambda-promise-test at gifted-kalam-e7b693.netlify.com.
I think this would be a good feature to support but not until Netlify itself supports it, which I think @ThomasEdwards is alluding too when he suggests this is a feature request (for Netlify Functions itself, not netlify-lambda) and not a bug. @sw-yx anywhere in particular we should +1 this as a feature request for Netlify Functions? |
theres no open voting system here but your suggestion is valued and noted. fwiw we actually dont use API Gateway for Netlify Functions. its probably something else but i dont know enough to tell you what it is. will shoot this over to the product/support folk as a feature request. i'm a little worried that it may break behavior folks currently rely on. |
My hope was that if a user is still using callbacks, then no change would be required. As currently you cannot return a |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
boop |
boop boop |
With Node 8.10 and #24 merged in to 0.4.0, we can now return promises 👌 (thanks @leonardodino)
However, it doesn’t behave the same way Lambda does.
Using 8.10, you can return a promise to Lambda. It reads the resolve as being a 200 (with the body), and a reject as a 500 (with the error).
However Netlify Lambda this doesn’t work yet:
This is using the test project I created to test with.
This should work, but just times out with the above error:
This does work:
So promises are being resolved, but it's not allowing it to return a promise. Now I’m new to promises, so this suggestion might be wrong or there might be a better way, but if we change this:
to this:
Then it will work – but I’m not sure how safe this is or if it’s a good idea or not.
The text was updated successfully, but these errors were encountered: