question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug - Amplify/Lambda reporting uninformative errors

See original GitHub issue

I describe my issue at length on Stack Overflow, but I’m unsure if it is an Amplify bug, so I’m reproducing it (more briefly) here.

Basically, when I return a response from an API Gateway/Lambda with an error statusCode (>= 400), Amplify on the frontend catches the error (good), but the error has none of the information in my structured Lambda response. Instead it’s just a Network Error, with no helpful information.

As in, the below is a successful response:

{
    "statusCode": 200,
    "headers": {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Credentials": true
    },
    "body": "{ /* whatever */ }"
}

And I’m returning this on the Lambda end like so:

callback(null, objectShownAbove);

But if I change that 200 to a 400 in my Lambda, the catch on the frontend’s Amplify.get promise is called (as it should be), and/but the error argument is a generic Network Error that doesn’t reference my response body or anything.

Error: Network Error
    at createError (createError.js:16)
    at XMLHttpRequest.handleError (xhr.js:87)

Additionally, the frontend console logs some other non-specific errors (complaining about the response headers, which are identical to the success condition):

GET https://abcdefg.execute-api.us-west-2.amazonaws.com/development/my-endpoint 403 ()

Failed to load https://abcdefg.execute-api.us-west-2.amazonaws.com/development/my-endpoint: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 403.

And info about CORB issues, which doesn’t seem sensible, given that a success response works, and all that’s changed is the statusCode number.

Cross-Origin Read Blocking (CORB) blocked cross-origin response https://abcdefg.execute-api.us-west-2.amazonaws.com/development/my-endpoint with MIME type application/json.
XHR failed loading: GET "https://abcdefg.execute-api.us-west-2.amazonaws.com/development/my-endpoint".

Is this an Amplify bug? A Lambda bug? Am I doing something wrong?

Thanks.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mlabienieccommented, Aug 31, 2018

This does end up depending on how you configure your API Gateway, e.g. Lambda proxy etc. If you are NOT using a Lambda proxy setup, you will need to map these error responses/codes within API Gateway, see extensive post on that here: https://aws.amazon.com/blogs/compute/error-handling-patterns-in-amazon-api-gateway-and-aws-lambda/

If you are using a Lambda Proxy, you will just return as a specific type of proxy response from Lambda: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-as-simple-proxy-for-lambda.html

0reactions
github-actions[bot]commented, Jun 12, 2021

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 or Discussions for those types of questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot CloudFormation stack issues in AWS Amplify
When I try to deploy my AWS Amplify application, I receive an AWS CloudFormation error similar to the following: "Resource is not in...
Read more >
AWS Lambda: Task timed out - Stack Overflow
Your error message says Task timed out after 15.00 seconds . This means that AWS intentionally stopped the task once it hit a...
Read more >
Add monitoring to your Amplify app by using Amplify framework
Step 3: Get notified when your function executes but logged errors. Until now, we're being set up Cloud Watch alarms based on AWS...
Read more >
Enable Slack Notifications for AWS Amplify Deployments
AWS Amplify is a set of purpose-built tools and features that lets front-end web and ... .catch((e) => console.error(e.response.data)) }.
Read more >
Pros and cons of Amplify Mock - LinkedIn
This procedure would be very time-consuming and since debugging lambda functions in the cloud is only possible via logging statements, error ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found