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

Errors are not returned in Lambda Resolvers #6067

Closed
half2me opened this issue Dec 4, 2020 · 4 comments · Fixed by #6096
Closed

Errors are not returned in Lambda Resolvers #6067

half2me opened this issue Dec 4, 2020 · 4 comments · Fixed by #6096
Assignees
Labels
bug Something isn't working mock Issues tied to the mock functionality
Projects

Comments

@half2me
Copy link

half2me commented Dec 4, 2020

Describe the bug
Following the example here: https://docs.amplify.aws/cli/graphql-transformer/function I created a lambda resolver for one of my GraphQL queries. If I make an GraphQL query and my lambda function throws an error, it does not propagate to GraphQL. Instead, it just returns an empty response.

Amplify CLI Version
4.37.1

To Reproduce

  1. Generate a lambda resolver: amplify add function
  2. Add the @function directive to a GraphQL field
  3. In the lambda resolver, use this code for an example:
exports.handler = async (event) => {
  throw new Error("Foo");
}
  1. Run amplify mock
    If I just return some normal data, everything works fine, but as soon as I throw an error, my response is empty (GraphQL usually complains about missing fields at this point, because some of my fields are mandatory, and I'm not filling them out)

Expected behavior
Looking at the generated InvokeFooDataSource.res.vtl resolver mapping template, I see the following code:

## [Start] Handle error or return result. **
#if( $ctx.error )
  $util.error($ctx.error.message, $ctx.error.type)
#end
$util.toJson($ctx.result)
## [End] Handle error or return result. **

I would expect $ctx.error to contain my error object, but it is always empty.

Desktop (please complete the following information):

  • OS: Mac
  • Node Version: v12.20.0
@half2me
Copy link
Author

half2me commented Dec 4, 2020

@dabit3 this is the issue I mentioned on Discord

@attilah attilah added graphql-transformer-v1 Issue related to GraphQL Transformer v1 question General question documentation Add or update documentation labels Dec 7, 2020
@attilah attilah self-assigned this Dec 7, 2020
@attilah attilah added this to To do in Bug bash via automation Dec 7, 2020
@attilah attilah added bug Something isn't working mock Issues tied to the mock functionality and removed documentation Add or update documentation graphql-transformer-v1 Issue related to GraphQL Transformer v1 question General question labels Dec 7, 2020
@attilah
Copy link
Contributor

attilah commented Dec 7, 2020

@half2me I was able to reproduce it, #6096 fixes it.

@half2me
Copy link
Author

half2me commented Dec 7, 2020

thanks @attilah, much appreciated! 😃

Bug bash automation moved this from To do to Done Dec 11, 2020
@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working mock Issues tied to the mock functionality
Projects
Bug bash
  
Done
Development

Successfully merging a pull request may close this issue.

2 participants