dwyl / aws-sdk-mock

:rainbow: AWSomocks for Javascript/Node.js aws-sdk tested, documented & maintained. Contributions welcome!
Apache License 2.0
1.09k stars 107 forks source link

How to simulate errors? #92

Open nathanielks opened 7 years ago

nathanielks commented 7 years ago

Hiya, team!

Great job on the package, thanks for making this! I'm trying to figure out how I would simulate service throwing an error and I can't quite figure out how. Could you shed some light on the situation? Thank you!

nathanielks commented 7 years ago

Here's what I've tried thus far:

  AWS.mock('ECS', 'updateContainerInstancesState', (params) => {
    console.log(params)
    const err = 'boogers'
    return new Error(err)
  })
  AWS.mock('ECS', 'updateContainerInstancesState', (params) => {
    console.log(params)
    const err = 'boogers'
    throw new Error(err)
  })
jcgsville commented 6 years ago

Hi nathanielelks.

I was able to get this to work:

AWS.mock('DynamoDB.DocumentClient', 'put', function(params, callback) {
    callback(new Error(), null);
});
Bassadin commented 2 months ago

We recently upgraded from 5.5.0 to 5.9.0 and new Error() does not seem to work anymore:

 Overload 1 of 2, '(err: undefined, data: InvocationResponse): void', gave the following error.
        Argument of type 'Error' is not assignable to parameter of type 'undefined'.
      Overload 2 of 2, '(err: AWSError, data?: undefined): void', gave the following error.
        Argument of type 'Error' is not assignable to parameter of type 'AWSError'.
    652                 callback(error, params);