Closed ondrejmirtes closed 5 years ago
Hey happy to see you try this out ^^
That's actually a very good point π€ I've focused on http and cli and I didn't think too much about that.
I was going to say you could throw an exception, but Bref's PHP part will not catch it so the lambda (the JS handler) will consider that as a PHP error. The lambda will return an error, not something useful though:
https://github.com/mnapoli/bref/blob/master/template/handler.js#L60
What Bref could do is catch exceptions and return the message of that exception to handler.js
, that way the result of the lambda is marked as errored and the message will be the one of the PHP exception, WDYT?
However if you have more specific needs (returning additional data from the error) I guess you'll need to return data manually in the JSON.
Also be aware that by default, when a lambda fails, it is retried 3 times. For my prettyci jobs I disabled that. Also I directly update the GitHub status and call my API to report the build result, I don't have anything waiting for the lambdas/workers result.
that way the result of the lambda is marked as errored and the message will be the one of the PHP exception, WDYT?
Yeah, it would be nice, but I need to differentiate between "expected exceptions" and "unexpected exceptions" - if something fails hard, I want to log it (via a top level error handler, for example registered by Sentry/Raven) and return a general error message like "An error occured." This could be compared to a general "HTTP 500" error in traditional web apps. In this case I don't want to propagate the exception error message because it might not be useful for the user.
But I also want to return expected errors - when user does something that blocks the request from being handled, but I expect this, like a parse error in the passed code example. This might be compared to "HTTP 422".
Usually MVC frameworks solve this by special handling of "ResponseException" and they propagate the error message to the response body itself. Any other exception that's not subtype of "ResponseException" is handled as a general error and results in "HTTP 500". Of course the naming is up to you π
But I think it would be useful if Bref did something similar.
The expected "ResponseException" also does not get rethrown to the top error handler, but any other exception does.
In v0.3 errors/exceptions are caught by the runtime and a reported to AWS Lambda as an invocation error. This error contains the message of the exception (and the class name and stack trace).
Does that sound good?
If you want any other behavior to happen (e.g. avoid reporting internal exceptions to the caller) then you will need to wrap your code in a try/catch and rethrow a generic exception.
To me it makes sense.
Yes, itβs okay π
On Sat, 5 Jan 2019 at 22:31, Matthieu Napoli notifications@github.com wrote:
In v0.3 errors/exceptions are caught by the runtime and a reported to AWS Lambda as an invocation error. This error contains the message of the exception (and the class name and stack trace).
Does that sound good?
If you want any other behavior to happen (e.g. avoid reporting internal exceptions to the caller) then you will need to wrap your code in a try/catch and rethrow a generic exception.
To me it makes sense.
β You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mnapoli/bref/issues/87#issuecomment-451692015, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGZuEbRAdi_uKUVo2qt-uaRf-wUEjGZks5vARm-gaJpZM4YZb2O .
--
OndΕej Mirtes
Hi Matthieu, thank you very much for this package, you've done a really good job for helping people to deploy PHP to Lambda seamlessly! I will be bothering you with some issues and findings from my recent experiences with Bref π
I'm using
simpleHandler
to provide a Lambda function that is used by other Lambda functions (those other functions are written in JS and provide a layer for authentication etc.). I'd like to indicate that thesimpleHandler
wasn't successful, in a native way as most as possible. What should I use for that?I'm invoking the Lambda in TypeScript like this:
Since it's not an HTTP request, I don't think that
StatusCode
will be populated with anything useful. Ideally, theinvoke
promise call should throw an AWSError so i cancatch
it.I'm aware that I can always do my custom protocol, having the returned JSON have something like
error
key but I'd like to avoid that.Thank you!