aws-sdk-js-v3 icon indicating copy to clipboard operation
aws-sdk-js-v3 copied to clipboard

Fix NPE where data.Error is undefined from a 400 response

Open mjgp2 opened this issue 2 years ago • 3 comments

Description

Sometimes (seemingly on a 400 response) the Error is undefined, and data.Error.Code throws a NPE.

Testing

Existing tests should suffice.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

mjgp2 avatar May 03 '22 17:05 mjgp2

Thanks for your PR. I believe this needs a corresponding change in the 🪀 🐶 code that generates the code, as seen in what https://github.com/aws/aws-sdk-js-v3/pull/3085 is getting at.

There is no clear indication at the moment that you are editing generated code, but there is a PR open to change that: https://github.com/awslabs/smithy-typescript/pull/538.

kuhe avatar May 03 '22 18:05 kuhe

Hi @mjgp2 Can you also share the content of data when error code cannot be parsed? It'll be helpful to use to roll out a correct fix.

AllanZhengYP avatar May 03 '22 19:05 AllanZhengYP

We are hitting the same and similar issues. The proposed fix is only partial.

This is a sample of SQS 400 error (for a DeleteMessage with an invalid receipt):

Errors: {
    Error: {
      Code: 'ReceiptHandleIsInvalid',
      Message: 'The input receipt handle is invalid.'
    }
  },
  RequestId: 'PFS6BZ1KB4DNYC9BQ0N6MWQHX0XKVKTSQZRJ9WXSK6WC9AK0CPOS'

Error is wrapped inside Errors which means code isn't found and we get back a type error rather than a sensible actionable error.

Some 400s return correctly like this one (for SendMessage with large message):

{
  xmlns: 'http://queue.amazonaws.com/doc/2012-11-05/',
  Error: {
    Type: 'Sender',
    Code: 'InvalidParameterValue',
    Message: 'One or more parameters are invalid. Reason: Message must be shorter than 262144 bytes.',
    Detail: ''
  },
  RequestId: 'OLBR5M8PNYFNXHL20G90AINDLBABVK8GNINGS03SLDEIJYG3G42U'
}

I have also seen errors return without Error property at all but I don't have a current example.

This does cause us some issues with migrating from v2 to v3 which handled these errors properly.

eliran avatar Jul 14 '22 21:07 eliran

@mjgp2 did you have any updates on this? i am running into this and its obfuscating a small percentage of our API errors, preventing us from knowing what's actually going on. specifically, around 1/100000 calls to SNS PublishMessage when publishing to a push notification (APNS / GCM) endpoint are failing with this NPE. Specifically

Failed to execute PublishMessage command: Cannot read properties of undefined (reading 'Code')

Tetramputechture avatar Jan 09 '23 17:01 Tetramputechture

This was replicated in https://github.com/aws/aws-sdk-js-v3/pull/4367

kuhe avatar Jan 31 '23 01:01 kuhe

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

github-actions[bot] avatar Feb 15 '23 00:02 github-actions[bot]