How to force an exception
See original GitHub issueI am using this library in my tests and so far it is great. However I am a unsure about how to use this to force an exception.
for example I am doing this
const {
DynamoDBDocumentClient,
UpdateCommand,
} = require('@aws-sdk/lib-dynamodb');
const {
ConditionalCheckFailedException,
} = require('@aws-sdk/client-dynamodb');
const ddbMock = mockClient(DynamoDBDocumentClient);
ddbMock.on(UpdateCommand).rejects(ConditionalCheckFailedException);
However that does not throw the proper exception. Any ideas on what I need to do differently?
The code I am testing looks like this
if (error instanceof ConditionalCheckFailedException) {
...
}
For reference: https://aws.amazon.com/blogs/developer/service-error-handling-modular-aws-sdk-js/ https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.DynamoDb.Exception.DynamoDbException.html#shape-conditionalcheckfailedexception
Issue Analytics
- State:
- Created a year ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How to Throw Exceptions (The Java™ Tutorials > Essential ...
Most programs throw and catch objects that derive from the Exception class. An Exception indicates that a problem occurred, but it is not...
Read more >How to Throw an Exception in Java | Webucator
Open your text editor and type in the following Java statements: Java Source for Throwing an Exception · Save your file as ThrowAnException.java...
Read more >How can I raise an error in if-else function in java
Here you go: throw new java.lang.Error("this is very bad");. More idiomatic to throw a subclass of Exception. RuntimeException in particular is unchecked ...
Read more >Creating and Throwing Exceptions | Microsoft Learn
Learn about creating and throwing exceptions. Exceptions are used to indicate that an error has occurred while running a program.
Read more >How can an exception be thrown manually by a programmer ...
To throw an exception explicitly you need to instantiate the class of it and throw its object using the throw keyword.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The
ConditionalCheckFailedException
constructor requires themessage
and$metadata
properties, so the correct way to create it withoutany
would be:Actually, I was able to work around this with
ddbMock.on(UpdateCommand).rejects(new ConditionalCheckFailedException('' as any));